问:
Properly (independent of 32bit/64bit) saving a float to binary ofstream
So apparently on my machine, float, double and long double each have different sizes each. There also doesn't seem to be a strict standard enforcing how many bytes each of those types would have to be.

How would one, then, save a floating point value into a binary file, and then have it read properly on a different system if the sizes differ? e.g my machine has 8 byte doubles, whereas joe's have 12 byte doubles.

Without having to export it in text form (e.g "0.3232"), that is. Seems a lot less compact than the binary representation.

答:
You have to define a format, and implement that.  Typically, most of the
network protocols I know use IEEE float and double, output big-endian
(but other formats are possible).  The advantage of using IEEE formats
is that it is what most of the current everyday machines use
internally; if you're on one of these machines (and portability of your
code to other machines, like mainframes, isn't an issue), you can
"convert" to the format simply by type-punning to an unsigned int of the
same size, and outputting that.  So, for example, you might have:

```<code>obstream&
operator<<( obstream& dest, uint64_t value )
{
    dest.put((value >> 56) & 0xFF);
    dest.put((value >> 48) & 0xFF);
    dest.put((value >> 40) & 0xFF);
    dest.put((value >> 32) & 0xFF);
    dest.put((value >> 24) & 0xFF);
    dest.put((value >> 16) & 0xFF);
    dest.put((value >>  8) & 0xFF);
    dest.put((value      ) & 0xFF);
    return dest;
}

obstream&
operator<<( obstream& dest, double value )
{
    return dest << reinterpret_cast<uint64_t const&>( value );
}
</code>```

If you have to be portable to a machine not supporting IEEE (e.g. any of
the modern mainframes), you'll need something a bit more complicated:

```<code>obstream&
obstream::operator<<( obstream& dest, double value )
{
    bool                isNeg = value < 0;
    if ( isNeg ) {
        value = - value;
    }
    int                 exp;
    if ( value == 0.0 ) {
        exp = 0;
    } else {
        value = ldexp( frexp( value, &exp ), 53 );
        exp += 1022;
    }
    uint64_t mant = static_cast< uint64_t >( value );
    dest.put( (isNeg ? 0x80 : 0x00) | exp >> 4 );
    dest.put( ((exp << 4) & 0xF0) | ((mant >> 48) & 0x0F) );
    dest.put( mant >> 40 );
    dest.put( mant >> 32 );
    dest.put( mant >> 24 );
    dest.put( mant >> 16 );
    dest.put( mant >>  8 );
    dest.put( mant       );
    return dest;
}
</code>```

(Note that this doesn't handle NaN's and infinities correctly.
Personally, I would ban them from the format, since not all floating
point representations support them.  But then, there's no floating point
format on an IBM mainframe which will support 1E306, either, although
you can encode it in the IEEE double format above.)

Reading is, of course, the opposite.  Either:

```<code>ibstream&
operator>>( ibstream& source, uint64_t& results )
{
    uint64_t value = (source.get() & 0xFF) << 56;
    value |= (source.get() & 0xFF) << 48;
    value |= (source.get() & 0xFF) << 40;
    value |= (source.get() & 0xFF) << 32;
    value |= (source.get() & 0xFF) << 24;
    value |= (source.get() & 0xFF) << 16;
    value |= (source.get() & 0xFF) <<  8;
    value |= (source.get() & 0xFF)      ;
    if ( source )
        results = value;
    return source;
}

ibstream&
operator>>( ibstream& source, double& results)
{
    uint64_t tmp;
    source >> tmp;
    if ( source )
        results = reinterpret_cast<double const&>( tmp );
    return source;
}
</code>```

or if you can't count on IEEE:

```<code>ibstream&
ibstream::operator>>( ibstream& source, double& results )
{
    uint64_t tmp;
    source >> tmp;
    if ( source ) {
        double f = 0.0;
        if ( (tmp & 0x7FFFFFFFFFFFFFFF) != 0 ) {
            f = ldexp( ((tmp & 0x000FFFFFFFFFFFFF) | 0x0010000000000000),
                       static_cast<int>( (tmp & 0x7FF0000000000000) >> 52 )
                                - 1022 - 53 );
        }
        if ( (tmp & 0x8000000000000000) != 0 ) {
            f = -f;
        }
        dest = f;
    }
    return source;
}
</code>```

(This assumes that the input is not an NaN or an infinity.)

Body:
You have to define a format, and implement that.  Typically, most of the
network protocols I know use IEEE float and double, output big-endian
(but other formats are possible).  The advantage of using IEEE formats
is that it is what most of the current everyday machines use
internally; if you're on one of these machines (and portability of your
code to other machines, like mainframes, isn't an issue), you can
"convert" to the format simply by type-punning to an unsigned int of the
same size, and outputting that.  So, for example, you might have:

obstream&
operator<<( obstream& dest, uint64_t value )
{
    dest.put((value >> 56) & 0xFF);
    dest.put((value >> 48) & 0xFF);
    dest.put((value >> 40) & 0xFF);
    dest.put((value >> 32) & 0xFF);
    dest.put((value >> 24) & 0xFF);
    dest.put((value >> 16) & 0xFF);
    dest.put((value >>  8) & 0xFF);
    dest.put((value      ) & 0xFF);
    return dest;
}

obstream&
operator<<( obstream& dest, double value )
{
    return dest << reinterpret_cast<uint64_t const&>( value );
}

If you have to be portable to a machine not supporting IEEE (e.g. any of
the modern mainframes), you'll need something a bit more complicated:

obstream&
obstream::operator<<( obstream& dest, double value )
{
    bool                isNeg = value < 0;
    if ( isNeg ) {
        value = - value;
    }
    int                 exp;
    if ( value == 0.0 ) {
        exp = 0;
    } else {
        value = ldexp( frexp( value, &exp ), 53 );
        exp += 1022;
    }
    uint64_t mant = static_cast< uint64_t >( value );
    dest.put( (isNeg ? 0x80 : 0x00) | exp >> 4 );
    dest.put( ((exp << 4) & 0xF0) | ((mant >> 48) & 0x0F) );
    dest.put( mant >> 40 );
    dest.put( mant >> 32 );
    dest.put( mant >> 24 );
    dest.put( mant >> 16 );
    dest.put( mant >>  8 );
    dest.put( mant       );
    return dest;
}

(Note that this doesn't handle NaN's and infinities correctly.
Personally, I would ban them from the format, since not all floating
point representations support them.  But then, there's no floating point
format on an IBM mainframe which will support 1E306, either, although
you can encode it in the IEEE double format above.)

Reading is, of course, the opposite.  Either:

ibstream&
operator>>( ibstream& source, uint64_t& results )
{
    uint64_t value = (source.get() & 0xFF) << 56;
    value |= (source.get() & 0xFF) << 48;
    value |= (source.get() & 0xFF) << 40;
    value |= (source.get() & 0xFF) << 32;
    value |= (source.get() & 0xFF) << 24;
    value |= (source.get() & 0xFF) << 16;
    value |= (source.get() & 0xFF) <<  8;
    value |= (source.get() & 0xFF)      ;
    if ( source )
        results = value;
    return source;
}

ibstream&
operator>>( ibstream& source, double& results)
{
    uint64_t tmp;
    source >> tmp;
    if ( source )
        results = reinterpret_cast<double const&>( tmp );
    return source;
}

or if you can't count on IEEE:

ibstream&
ibstream::operator>>( ibstream& source, double& results )
{
    uint64_t tmp;
    source >> tmp;
    if ( source ) {
        double f = 0.0;
        if ( (tmp & 0x7FFFFFFFFFFFFFFF) != 0 ) {
            f = ldexp( ((tmp & 0x000FFFFFFFFFFFFF) | 0x0010000000000000),
                       static_cast<int>( (tmp & 0x7FF0000000000000) >> 52 )
                                - 1022 - 53 );
        }
        if ( (tmp & 0x8000000000000000) != 0 ) {
            f = -f;
        }
        dest = f;
    }
    return source;
}

(This assumes that the input is not an NaN or an infinity.)


来源: stackexchange

问:
Find contents between square brackets and quotations
So to put it straight, lets say I have this string:

command [stuff] [stuff [inside] this] "string" "another [thing] string"

Inside of my code I want to grab all the things with quotation marks and put them in an array and grab all the things inside of outer most brackets (everything inside of the outside brackets) and put them in their own array. Like so:

const string = `command [stuff] [stuff [inside] this] "string" "another [thing] string"`;

let quotations = ["string", "another [thing] string"]
let brackets = ["stuff", "stuff [inside] this"] // I do not want to include any brackets found inside of quotation marks
```
<p>I have tried to make a regex that would do this, but I am just having a lot of trouble understanding how I would set it up. I did find these two regex which find the stuff in quotations and brackets but they aren't 100% what I am looking for:</p>
<pre class="lang-js prettyprint-override"><code>// JavaScript Regex
const regexStrings = /(["'])(?:(?=(\\?))\2.)*?\1/g;
const regexBrackets = /\[(.*?)\]/g;
</code>```

答:
Suppose the given string is as follows.

```<code>'command [stuff] [stuff [inside] this] "string" "another [thing] string"'
          bbbbb   bbbbbbbbbbbbbbbbbbb   dddddd   dddddddddddddddddddddd
</code>```

We wish to extract the values marked bbb... (within brackets) to one array and values marked ddd... (within double-quotes) to a second array.  This can be done in two steps.

Step 1: extract all strings within double-quotes and replace those matches, including the surrounding double-quotes, with empty strings

Replace matches of the following regular expression (with the g flag set) with empty strings.1

```<code>"([^"]*)"
</code>```

That will return

```<code>'command [stuff] [stuff [inside] this]  '
          bbbbb   bbbbbbbbbbbbbbbbbbb
</code>```

which we will use in the second step, as shown below.

As well, the contents of capture group 1 will be 'string' and 'another [thing] string', which we must save.

Demo 1

This expression reads, "match a double-quote followed by zero or more characters other than a double-quote, followed by a double-quote, with the sting bounded by the double-quotes saved to capture group 1".

Step 2: extract all strings delimited with brackets that are not within a string that is delimited with brackets

We can obtain the strings of interest ('stuff' and 'stuff [inside] this') by matching the regular expression

```<code>(?<=\[)[^\[\]]*(?:\[[^\[\]]*\])?[^\[\]]*(?=\])
</code>```

Demo 2

This expression can be broken down as follows.

```<code>(?<=\[)     # positive lookbehind asserts match is preceded by '['
[^\[\]]*    # match 0+ chars other than '[' and ']'
(?:         # begin non-capture group
  \[        # match '['
  [^\[\]]*  # match 0+ chars other than '[' and ']'
  \]        # match ']'
)?          # end non-capture group and make it optional
[^\[\]]*    # match 0+ chars other than '[' and ']'
(?=\])      # positive lookahead asserts match is followed by ']'
</code>```

Note that this expression does not work with more than one level of nesting, such as

```<code>'[stuff [inside [stuff] like] this]'
  bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
</code>```

The regular expression I've given could be modified to handle up to any given number of levels of nesting by extending the approach I have taken, but it becomes unwieldy for more than three levels of nesting.

1. Alternatively, we could write "(.*?)". Making .* lazy (?) prevents the match from gobbling up characters, including double-quotes, until the last double-quote in the string is reached. If we were to use ".*" (a greedy match) we would obtain the single match, '"string" "another [thing] string'".

ContentLicense: CC BY-SA 4.0

Body:
So to put it straight, lets say I have this string:

command [stuff] [stuff [inside] this] "string" "another [thing] string"

Inside of my code I want to grab all the things with quotation marks and put them in an array and grab all the things inside of outer most brackets (everything inside of the outside brackets) and put them in their own array. Like so:

const string = `command [stuff] [stuff [inside] this] "string" "another [thing] string"`;

let quotations = ["string", "another [thing] string"]
let brackets = ["stuff", "stuff [inside] this"] // I do not want to include any brackets found inside of quotation marks

I have tried to make a regex that would do this, but I am just having a lot of trouble understanding how I would set it up. I did find these two regex which find the stuff in quotations and brackets but they aren't 100% what I am looking for:

// JavaScript Regex
const regexStrings = /(["'])(?:(?=(\\?))\2.)*?\1/g;
const regexBrackets = /\[(.*?)\]/g;

Body:
Suppose the given string is as follows.

'command [stuff] [stuff [inside] this] "string" "another [thing] string"'
          bbbbb   bbbbbbbbbbbbbbbbbbb   dddddd   dddddddddddddddddddddd

We wish to extract the values marked bbb... (within brackets) to one array and values marked ddd... (within double-quotes) to a second array.  This can be done in two steps.

Step 1: extract all strings within double-quotes and replace those matches, including the surrounding double-quotes, with empty strings

Replace matches of the following regular expression (with the g flag set) with empty strings.1

"([^"]*)"

That will return

'command [stuff] [stuff [inside] this]  '
          bbbbb   bbbbbbbbbbbbbbbbbbb

which we will use in the second step, as shown below.

As well, the contents of capture group 1 will be 'string' and 'another [thing] string', which we must save.

Demo 1

This expression reads, "match a double-quote followed by zero or more characters other than a double-quote, followed by a double-quote, with the sting bounded by the double-quotes saved to capture group 1".

Step 2: extract all strings delimited with brackets that are not within a string that is delimited with brackets

We can obtain the strings of interest ('stuff' and 'stuff [inside] this') by matching the regular expression

(?<=\[)[^\[\]]*(?:\[[^\[\]]*\])?[^\[\]]*(?=\])

Demo 2

This expression can be broken down as follows.

(?<=\[)     # positive lookbehind asserts match is preceded by '['
[^\[\]]*    # match 0+ chars other than '[' and ']'
(?:         # begin non-capture group
  \[        # match '['
  [^\[\]]*  # match 0+ chars other than '[' and ']'
  \]        # match ']'
)?          # end non-capture group and make it optional
[^\[\]]*    # match 0+ chars other than '[' and ']'
(?=\])      # positive lookahead asserts match is followed by ']'

Note that this expression does not work with more than one level of nesting, such as

'[stuff [inside [stuff] like] this]'
  bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

The regular expression I've given could be modified to handle up to any given number of levels of nesting by extending the approach I have taken, but it becomes unwieldy for more than three levels of nesting.

1. Alternatively, we could write "(.*?)". Making .* lazy (?) prevents the match from gobbling up characters, including double-quotes, until the last double-quote in the string is reached. If we were to use ".*" (a greedy match) we would obtain the single match, '"string" "another [thing] string'".


问:
Github Pages can't find Jekyll theme "Minimal Mistakes"
I've made a personal blog with Jakyll on Github Pages, it was working flawlessly with the default theme.

Then I've (locally) installed the theme Minimal Mistakes and worked on it to add some customizations. It works fine locally.

I'm using VS Code on Windows 10.

I then committed and synced the repo but GitHub Pages can't load the new theme apparently. The blog still works with the old one but I've got this error message from GitHUb Pages:

```<code>/usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:84:in `rescue in gemspec': The minimal-mistakes-jekyll theme could not be found. (Jekyll::Errors::MissingDependencyException)
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:81:in `gemspec'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:19:in `root'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:12:in `initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in `new'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in `configure_theme'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:55:in `config='
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:23:in `initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in `new'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in `process'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:70:in `block (3 levels) in <top (required)>'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:6:in `<top (required)>'
from /usr/local/bundle/bin/github-pages:23:in `load'
from /usr/local/bundle/bin/github-pages:23:in `<main>'
</code>```

/usr/local/lib/ruby/2.7.0/rubygems/dependency.rb:311:in to_specs': Could not find 'minimal-mistakes-jekyll' (>= 0) among 159 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/github/home/.gem/ruby/2.7.0:/usr/local/lib/ruby/gems/2.7.0:/usr/local/bundle', execute gem envfor more information from /usr/local/lib/ruby/2.7.0/rubygems/dependency.rb:323:into_spec'
from /usr/local/lib/ruby/2.7.0/rubygems/specification.rb:986:in find_by_name' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:82:in gemspec'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:19:in root' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:12:in initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in new' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in configure_theme'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:55:in config=' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:23:in initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in new' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in process'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:70:in block (3 levels) in <top (required)>' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in block in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in each' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in go' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in program'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:6:in <top (required)>' from /usr/local/bundle/bin/github-pages:23:in load'
from /usr/local/bundle/bin/github-pages:23:in `'
Logging at level: debug
Configuration file: /github/workspace/./_config.yml
Theme: minimal-mistakes-jekyll
github-pages 223 | Error:  The minimal-mistakes-jekyll theme could not be found.

I've originally installed (and developed the whole blog) Ruby 3.0.
I suspect GitHub Pages needs 2.7.0?

You can have a look at my repo here

答:
I was confusing the use of the remote theme plugin with the Gem theme method, doing a bit of both locally. I've cleaned up my Gemfile and my _config.yml and now it's all working properly.

The fact that I used Ruby 3.0 locally and then Github Pages uses 2.7 doesn't matter apparently.

Body:
I've made a personal blog with Jakyll on Github Pages, it was working flawlessly with the default theme.

Then I've (locally) installed the theme Minimal Mistakes and worked on it to add some customizations. It works fine locally.

I'm using VS Code on Windows 10.

I then committed and synced the repo but GitHub Pages can't load the new theme apparently. The blog still works with the old one but I've got this error message from GitHUb Pages:

/usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:84:in `rescue in gemspec': The minimal-mistakes-jekyll theme could not be found. (Jekyll::Errors::MissingDependencyException)
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:81:in `gemspec'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:19:in `root'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:12:in `initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in `new'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in `configure_theme'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:55:in `config='
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:23:in `initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in `new'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in `process'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:70:in `block (3 levels) in <top (required)>'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:6:in `<top (required)>'
from /usr/local/bundle/bin/github-pages:23:in `load'
from /usr/local/bundle/bin/github-pages:23:in `'

/usr/local/lib/ruby/2.7.0/rubygems/dependency.rb:311:in to_specs': Could not find 'minimal-mistakes-jekyll' (>= 0) among 159 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/github/home/.gem/ruby/2.7.0:/usr/local/lib/ruby/gems/2.7.0:/usr/local/bundle', execute gem envfor more information from /usr/local/lib/ruby/2.7.0/rubygems/dependency.rb:323:into_spec'
from /usr/local/lib/ruby/2.7.0/rubygems/specification.rb:986:in find_by_name' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:82:in gemspec'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:19:in root' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/theme.rb:12:in initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in new' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:439:in configure_theme'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:55:in config=' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/site.rb:23:in initialize'
from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in new' from /usr/local/bundle/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:30:in process'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:70:in block (3 levels) in <top (required)>' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in block in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in each' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in execute'
from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in go' from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in program'
from /usr/local/bundle/gems/github-pages-223/bin/github-pages:6:in <top (required)>' from /usr/local/bundle/bin/github-pages:23:in load'
from /usr/local/bundle/bin/github-pages:23:in `'
Logging at level: debug
Configuration file: /github/workspace/./_config.yml
Theme: minimal-mistakes-jekyll
github-pages 223 | Error:  The minimal-mistakes-jekyll theme could not be found.

I've originally installed (and developed the whole blog) Ruby 3.0.
I suspect GitHub Pages needs 2.7.0?

You can have a look at my repo here


问:
how to upload all type of file to cloudinary using django with filefield
hello guys i want to upload  all type of file to cloudinary
this is my model
i  don't want to  upload a specific kind of file but all  type
pleaze  help me

```<code>class post(models.Model):
titre=models.CharField(unique=True,null=True,max_length=100)
description=models.TextField(null=True,blank=True,max_length=400)
T=models.CharField(default="image",blank=True,max_length=50)
image=models.FileField(null=True)
cat=models.ForeignKey(categorie,on_delete=models.CASCADE,null=True)
datepost=models.DateTimeField(auto_now_add=True,blank=True)
user=models.ForeignKey(myuser,on_delete=models.CASCADE,null=True)
vue=models.IntegerField(default=0,blank=True)
def __str__(self):
    return self.titre

def save(self, *args ,**kwargs):
    #cette partie permet de generer un identifiant unique
    f=self.image.read(1000)
    self.image.seek(0)
    mime=magic.from_buffer(f,mime=True)
    if "video" in mime :
        self.T="short"
    super(post,self).save(*args,**kwargs)
</code>```

thanks for your helps and sorry for my bad english

答: Cloudinary does not allow you to upload all types of file , so if you want to upload any kind of file you need to use another object storage or use local media storage.</p>

Body:
hello guys i want to upload  all type of file to cloudinary
this is my model
i  don't want to  upload a specific kind of file but all  type
pleaze  help me

class post(models.Model):
titre=models.CharField(unique=True,null=True,max_length=100)
description=models.TextField(null=True,blank=True,max_length=400)
T=models.CharField(default="image",blank=True,max_length=50)
image=models.FileField(null=True)
cat=models.ForeignKey(categorie,on_delete=models.CASCADE,null=True)
datepost=models.DateTimeField(auto_now_add=True,blank=True)
user=models.ForeignKey(myuser,on_delete=models.CASCADE,null=True)
vue=models.IntegerField(default=0,blank=True)
def __str__(self):
    return self.titre

def save(self, *args ,**kwargs):
    #cette partie permet de generer un identifiant unique
    f=self.image.read(1000)
    self.image.seek(0)
    mime=magic.from_buffer(f,mime=True)
    if "video" in mime :
        self.T="short"
    super(post,self).save(*args,**kwargs)

thanks for your helps and sorry for my bad english


问:
Laravel 5.4 - MSSQL Error Invalid column name in Controller
I'm trying to add a column to a controller in Laravel 5.4 but when I do I get this error:

SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'Contract_SO_PO'.

Note: This is a new column in the database I recently created

Here is the code - I added 'contract.Contract_SO_PO' at the end of my select statement and in the groupBy:

```<code>public function index()
    {$records = DB::table('Contract')
            ->leftJoin('Contract_Line', 'Contract.Contract_ID','=','Contract_Line.Contract_ID')
            ->leftJoin('Contract_Product_Support_Bridge', 'Contract_Product_Support_Bridge.Contract_Line_ID','=','Contract_Line.Contract_Line_ID')
            ->leftJoin('Customer', 'Contract.Customer_ID','=','Customer.Customer_ID')
            ->select('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO', DB::raw('COUNT(*) AS Count_Records'))
            ->groupBy('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO')
            ->orderBy('Contract.Contract_ID','desc')
            ->get();

        return view('multi_records.index')->with('records',$records);
}
</code>```

I tested the code with a column I know previously exists in the database and the code ran just fine.

Any suggestions? I'm wondering if this is an issue of Laravel not connecting to the database properly and therefore not reflecting new changes.

答: I figured out the problem. I misconfigured my .env file to point to a different database than the one I was using. That was why database changes were not reflected.</p>

Body:
I'm trying to add a column to a controller in Laravel 5.4 but when I do I get this error:

SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'Contract_SO_PO'.

Note: This is a new column in the database I recently created

Here is the code - I added 'contract.Contract_SO_PO' at the end of my select statement and in the groupBy:

public function index()
    {$records = DB::table('Contract')
            ->leftJoin('Contract_Line', 'Contract.Contract_ID','=','Contract_Line.Contract_ID')
            ->leftJoin('Contract_Product_Support_Bridge', 'Contract_Product_Support_Bridge.Contract_Line_ID','=','Contract_Line.Contract_Line_ID')
            ->leftJoin('Customer', 'Contract.Customer_ID','=','Customer.Customer_ID')
            ->select('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO', DB::raw('COUNT(*) AS Count_Records'))
            ->groupBy('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO')
            ->orderBy('Contract.Contract_ID','desc')
            ->get();

        return view('multi_records.index')->with('records',$records);
}

I tested the code with a column I know previously exists in the database and the code ran just fine.

Any suggestions? I'm wondering if this is an issue of Laravel not connecting to the database properly and therefore not reflecting new changes.


问:
Send Array of hashes to class to create a user from each
I have a array of hashes

```<code>pets = [
    {
    "firstName": "Brianna",
     "lastName": "Parson",
     "children": ["sam","Joe"],
     "buddys": {

    },

    {
     "firstName": "jeffery",
     "lastName": "thomas",

     }
     }
    ]
</code>```

How do you send a class an array of hashes?

答:
You don't need anything that initialize method.I passed the hash the initialize method

  def initialize(user)
    @users = user
  end

```
<p>And also As you realized that, the users information in an array, so firstly, you should loop through the array and you should take all hash information with hash syntax.</p>
<pre class="lang-rb prettyprint-override"><code> def show_userhash
    @users.each do |user|
      puts "#{user[:firstName]} is a #{user[:job]} also has #{user[:pets].length} #{pet_num = user[:pets].length == 1 ? "pet" : "pets"} "
    end
  end
</code>```

When you made an instance of a class with a new method, first, the initialize method will execute and then, you should invoke the show_userhash method.

Here is the full code.

class Person

  def initialize(user)
    @users = user
  end

  def show_userhash
    @users.each do |user|
      puts "#{user[:firstName]} is a #{user[:job]} also has #{user[:pets].length} #{pet_num = user[:pets].length == 1 ? "pet" : "pets"} "
    end
  end
end

person_information  = [
      {
        "firstName": "Brianna",
        "lastName": "Parson",
        "job": "SOFTWARE ENGINEER",
        "totalAssetWorth": "2000.00",
        "totalDebt": "1500.00",
        "children": ["sam", "Joe"],
        "pets": {
          "dog": "jeff",
          "bird": "zoe"
        }
      },

      {
        "firstName": "Jeffery",
        "lastName": "thomas",
        "job": "Lawyer",
        "totalAssetWorth": "6000.00",
        "totalDebt": "1300.00",
        "children": [],
        "pets": {
          "cat": "gnocchi"
        }
      }
    ]
intro = Person.new(person_information)
intro.show_userhash

```

Body:
I have a array of hashes

pets = [
    {
    "firstName": "Brianna",
     "lastName": "Parson",
     "children": ["sam","Joe"],
     "buddys": {

    },

    {
     "firstName": "jeffery",
     "lastName": "thomas",

     }
     }
    ]

How do you send a class an array of hashes?

Body:
You don't need anything that initialize method.I passed the hash the initialize method

  def initialize(user)
    @users = user
  end

And also As you realized that, the users information in an array, so firstly, you should loop through the array and you should take all hash information with hash syntax.

 def show_userhash
    @users.each do |user|
      puts "#{user[:firstName]} is a #{user[:job]} also has #{user[:pets].length} #{pet_num = user[:pets].length == 1 ? "pet" : "pets"} "
    end
  end

When you made an instance of a class with a new method, first, the initialize method will execute and then, you should invoke the show_userhash method.

Here is the full code.

class Person

  def initialize(user)
    @users = user
  end

  def show_userhash
    @users.each do |user|
      puts "#{user[:firstName]} is a #{user[:job]} also has #{user[:pets].length} #{pet_num = user[:pets].length == 1 ? "pet" : "pets"} "
    end
  end
end

person_information  = [
      {
        "firstName": "Brianna",
        "lastName": "Parson",
        "job": "SOFTWARE ENGINEER",
        "totalAssetWorth": "2000.00",
        "totalDebt": "1500.00",
        "children": ["sam", "Joe"],
        "pets": {
          "dog": "jeff",
          "bird": "zoe"
        }
      },

      {
        "firstName": "Jeffery",
        "lastName": "thomas",
        "job": "Lawyer",
        "totalAssetWorth": "6000.00",
        "totalDebt": "1300.00",
        "children": [],
        "pets": {
          "cat": "gnocchi"
        }
      }
    ]
intro = Person.new(person_information)
intro.show_userhash


问:
How to reduce amount of Boolean statements when programming
So the current language I am using is flutter, although I believe this applies to any programming language. I am creating an app where I have a requirement to have an implemented custom keypad. The keypad has three configurations for three different text fields used in pipette.dart, I added part of the code for ASPIRATE SPEED and DISPENSE SPEED, althogh the same logic applies to volume shown in the image below.

When each text field is pressed the current highlight is switched to the container where the text field is ( The blue highlight below the text field). The keypad is also switched to control the text field which is pressed, shown in toggleKeyPad(). So for example when you click Aspirate Speed, isAspirate is true and isAspirateText is true, isAspirate is then passed to blueHighlightSpeed() (shown at the bottom of pipette.dart), which then highlights the container. when IsAspirateText is true it sets the keypad to use aspirateController which is the text editing controller for the text field in Aspirate Speed, the same logic applies to Dispense speed and Volume. Hopefully this helps anyone understand what my code is doing, I will update if I missed anything.

The question that I have is I would like to know if there is a way to minimize the amount of Boolean statements that I am using. Currently every time I click a new text field I have to change 8 different Booleans which can become very tedious and for other programmers will probably make the code harder to read and understand. I have only been programming for a few years now and would just like to know if there is a way to create this same logic without as many Booleans.

Is it maybe possible to use a switch statement here?

functions.dart

```<code>
import 'package:flutter/material.dart';
import '../keyboard/text_key.dart';
import '../keyboard/textkey_functions.dart';

bool keypadUp = false;
bool isTextFieldShown = false;
bool isVolume = false;
bool isVolumeText = false;
bool isAspirate = false;
bool isAspirateText = true;
bool isDispense = false;
bool isDispenseText = false;
bool depthMemoryTop = false;
bool depthMemoryBottom = false;

TextEditingController aspirateController = TextEditingController();
TextEditingController dispenseController = TextEditingController();
TextEditingController volumeController = TextEditingController();
TextEditingController machController = TextEditingController();

Widget toggleKeyPad() {
  if (isAspirateText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, aspirateController); //Accepts and inputs text into aspirateController
      },
      onBackspace: () {
        backspace(aspirateController);
      },
    );
  }
  if (isVolumeText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, volumeController); //Accepts and inputs text into volumeController
      },
      onBackspace: () {
        backspace(volumeController);
      },
    );
  }
  if (isDispenseText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, dispenseController); //Accepts and inputs text into dispenseController
      },
      onBackspace: () {
        backspace(dispenseController);
      },
    );
  } else {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, machController); // I didn't need the else statement so I created a fake controller which takes no input.
      },
      onBackspace: () {
        backspace(machController);
      },
    );
  }
}

Padding blueHighlightVolume (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 190),
      child: Container(
        width: 140,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 190),
      child: Container(
        width: 140,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightSpeed (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 1),
      child: Container(
        width: 140,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 1),
      child: Container(
        width: 140,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightDepthTop (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 89, left: 15),
      child: Container(
        width: 350,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightDepthBottom (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
      ),
    );
  }
}

</code>```

part of pipette.dart

```<code>                                 Column(
                                children: [
                                  Stack(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Text(
                                          'ASPIRATE SPEED',
                                          style: TextStyle(
                                            fontFamily: 'Droid Sans',
                                            color: Color.fromRGBO(2, 58, 107, 1),
                                            fontSize: 12.0,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        decoration: BoxDecoration(
                                          border: Border(
                                            left: BorderSide(width: 1, color: Colors.grey),
                                          ),
                                        ),
                                        width: 140,
                                        height: 100,
                                        //color: Colors.red,
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(left: 20.0, top: 36.0),
                                        child: Container(
                                          width: 75,
                                          height: 40,
                                          child: TextField(
                                            controller: aspirateController,
                                            textAlign: TextAlign.center,
                                            readOnly: true,
                                            onTap: () {
                                              setState(() {
                                                /*
                                                * set isAspirate and isAspirateText to true, highlights aspirate speed container and
                                                * changes aspirateController to accept input from the keypad.
                                                *
                                                */
                                                isAspirateText = true;
                                                isDispenseText = false;
                                                isVolumeText = false;
                                                isAspirate = true;
                                                isDispense = false;
                                                isVolume = false;
                                                depthMemoryTop = false;
                                                depthMemoryBottom = false;
                                                print(isAspirate);
                                              });
                                            },
                                            decoration: InputDecoration(
                                              border: OutlineInputBorder(),
                                            ),
                                          ),
                                        ),
                                      ),
                                      blueHighlightSpeed(isAspirate),
                                    ],
                                  ),
                                  Stack(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Text(
                                            'DISPENSE SPEED',
                                            style: TextStyle(
                                            fontFamily: 'Droid Sans',
                                            color: Color.fromRGBO(2, 58, 107, 1),
                                            fontSize: 12.0,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        decoration: BoxDecoration(
                                          border: Border(
                                            left: BorderSide(width: 1, color: Colors.grey),
                                          ),
                                        ),
                                        width: 140,
                                        height: 100,
                                        //color: Colors.red,
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(left: 20.0, top: 36.0),
                                        child: Container(
                                          width: 75,
                                          height: 40,
                                          child: TextField(
                                            controller: dispenseController,
                                            textAlign: TextAlign.center,
                                            readOnly: true,
                                            onTap: () {
                                              setState(() {
                                                isVolumeText = false;
                                                isAspirateText = false;
                                                isDispenseText = true;
                                                isAspirate = false;
                                                isDispense = true;
                                                isVolume = false;
                                                depthMemoryTop = false;
                                                depthMemoryBottom = false;
                                                print(isAspirate);
                                              });
                                            },
                                            decoration: InputDecoration(
                                              border: OutlineInputBorder(),
                                            ),
                                          ),
                                        ),
                                      ),
                                      blueHighlightSpeed(isDispense),
                                    ],
                                  ),
                                ],
                              ),

</code>```

keypad.dart

```<code>
class KeyPad extends StatelessWidget
{

  KeyPad({
    required this.onTextInput,
    required this.onBackspace,
  });

  final double width = 275;
  final double height = 90;

  final ValueSetter<String> onTextInput;
  final VoidCallback onBackspace;

  void _textInputHandler(String text) => onTextInput.call(text);

  void _backspaceHandler() => onBackspace.call();

  Container buildRowOne()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '7',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '8',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '9',
            onTextInput: _textInputHandler,
          ),

        ],
      ),
    );
  }

  Container buildRowTwo()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '4',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '5',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '6',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Container buildRowThree()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '1',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '2',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '3',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Container buildRowFour()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          BackspaceKey(
            onBackspace: _backspaceHandler,
          ),
          TextKey(
            text: '0',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '.',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Padding buildRowFive()
  {
    return Padding(
      padding: const EdgeInsets.only(top: 35),
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Color.fromRGBO(92, 103, 148, 1)),
              borderRadius: BorderRadius.circular(45.0),
        ),
        width: 175,
        height: 60,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            IconButton(
              icon: Image.asset('assets/text_key/done.png'),
              onPressed: () {},
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context)
  {
    return SafeArea(
      child: Container(
        child: Column(
          children: [
            buildRowOne(),
            buildRowTwo(),
            buildRowThree(),
            buildRowFour(),
            buildRowFive(),
          ],
        ),
      ),
    );
  }
}

</code>```

答:
The best thing to use in this situation would be a state machine, which would be much easier to implement than trying to use enumerations or switch statements -- which do not necessarily reduce the complexity of your code.

This video does a great job of explaining this:
https://www.youtube.com/watch?v=I1Mzx_tSpew

You don't need to know much about computational theory to implement a basic (finite) state machine, but it's a highly effective method for problems that can lead to infinite booleans.

Flutter also has access to a few good libraries for such a thing:

https://www.jawahar.tech/blog/finite-state-machine-flutter/ and
https://pub.dev/packages/statemachine

Body:
So the current language I am using is flutter, although I believe this applies to any programming language. I am creating an app where I have a requirement to have an implemented custom keypad. The keypad has three configurations for three different text fields used in pipette.dart, I added part of the code for ASPIRATE SPEED and DISPENSE SPEED, althogh the same logic applies to volume shown in the image below.

When each text field is pressed the current highlight is switched to the container where the text field is ( The blue highlight below the text field). The keypad is also switched to control the text field which is pressed, shown in toggleKeyPad(). So for example when you click Aspirate Speed, isAspirate is true and isAspirateText is true, isAspirate is then passed to blueHighlightSpeed() (shown at the bottom of pipette.dart), which then highlights the container. when IsAspirateText is true it sets the keypad to use aspirateController which is the text editing controller for the text field in Aspirate Speed, the same logic applies to Dispense speed and Volume. Hopefully this helps anyone understand what my code is doing, I will update if I missed anything.

The question that I have is I would like to know if there is a way to minimize the amount of Boolean statements that I am using. Currently every time I click a new text field I have to change 8 different Booleans which can become very tedious and for other programmers will probably make the code harder to read and understand. I have only been programming for a few years now and would just like to know if there is a way to create this same logic without as many Booleans.

Is it maybe possible to use a switch statement here?

functions.dart

import 'package:flutter/material.dart';
import '../keyboard/text_key.dart';
import '../keyboard/textkey_functions.dart';

bool keypadUp = false;
bool isTextFieldShown = false;
bool isVolume = false;
bool isVolumeText = false;
bool isAspirate = false;
bool isAspirateText = true;
bool isDispense = false;
bool isDispenseText = false;
bool depthMemoryTop = false;
bool depthMemoryBottom = false;

TextEditingController aspirateController = TextEditingController();
TextEditingController dispenseController = TextEditingController();
TextEditingController volumeController = TextEditingController();
TextEditingController machController = TextEditingController();

Widget toggleKeyPad() {
  if (isAspirateText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, aspirateController); //Accepts and inputs text into aspirateController
      },
      onBackspace: () {
        backspace(aspirateController);
      },
    );
  }
  if (isVolumeText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, volumeController); //Accepts and inputs text into volumeController
      },
      onBackspace: () {
        backspace(volumeController);
      },
    );
  }
  if (isDispenseText == true) {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, dispenseController); //Accepts and inputs text into dispenseController
      },
      onBackspace: () {
        backspace(dispenseController);
      },
    );
  } else {
    return KeyPad(
      onTextInput: (myText) {
        insertText(myText, machController); // I didn't need the else statement so I created a fake controller which takes no input.
      },
      onBackspace: () {
        backspace(machController);
      },
    );
  }
}

Padding blueHighlightVolume (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 190),
      child: Container(
        width: 140,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 190),
      child: Container(
        width: 140,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightSpeed (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 1),
      child: Container(
        width: 140,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 1),
      child: Container(
        width: 140,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightDepthTop (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 89, left: 15),
      child: Container(
        width: 350,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
      ),
    );
  }
}

Padding blueHighlightDepthBottom (bool isSelect) {
  if (isSelect == true) {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
        color: Color.fromRGBO(2, 58, 107, 1),
      ),
    );
  } else {
    return Padding(
      padding: const EdgeInsets.only(top: 90, left: 15),
      child: Container(
        width: 350,
        height: 10,
      ),
    );
  }
}

part of pipette.dart

                                 Column(
                                children: [
                                  Stack(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Text(
                                          'ASPIRATE SPEED',
                                          style: TextStyle(
                                            fontFamily: 'Droid Sans',
                                            color: Color.fromRGBO(2, 58, 107, 1),
                                            fontSize: 12.0,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        decoration: BoxDecoration(
                                          border: Border(
                                            left: BorderSide(width: 1, color: Colors.grey),
                                          ),
                                        ),
                                        width: 140,
                                        height: 100,
                                        //color: Colors.red,
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(left: 20.0, top: 36.0),
                                        child: Container(
                                          width: 75,
                                          height: 40,
                                          child: TextField(
                                            controller: aspirateController,
                                            textAlign: TextAlign.center,
                                            readOnly: true,
                                            onTap: () {
                                              setState(() {
                                                /*
                                                * set isAspirate and isAspirateText to true, highlights aspirate speed container and
                                                * changes aspirateController to accept input from the keypad.
                                                *
                                                */
                                                isAspirateText = true;
                                                isDispenseText = false;
                                                isVolumeText = false;
                                                isAspirate = true;
                                                isDispense = false;
                                                isVolume = false;
                                                depthMemoryTop = false;
                                                depthMemoryBottom = false;
                                                print(isAspirate);
                                              });
                                            },
                                            decoration: InputDecoration(
                                              border: OutlineInputBorder(),
                                            ),
                                          ),
                                        ),
                                      ),
                                      blueHighlightSpeed(isAspirate),
                                    ],
                                  ),
                                  Stack(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Text(
                                            'DISPENSE SPEED',
                                            style: TextStyle(
                                            fontFamily: 'Droid Sans',
                                            color: Color.fromRGBO(2, 58, 107, 1),
                                            fontSize: 12.0,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        decoration: BoxDecoration(
                                          border: Border(
                                            left: BorderSide(width: 1, color: Colors.grey),
                                          ),
                                        ),
                                        width: 140,
                                        height: 100,
                                        //color: Colors.red,
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(left: 20.0, top: 36.0),
                                        child: Container(
                                          width: 75,
                                          height: 40,
                                          child: TextField(
                                            controller: dispenseController,
                                            textAlign: TextAlign.center,
                                            readOnly: true,
                                            onTap: () {
                                              setState(() {
                                                isVolumeText = false;
                                                isAspirateText = false;
                                                isDispenseText = true;
                                                isAspirate = false;
                                                isDispense = true;
                                                isVolume = false;
                                                depthMemoryTop = false;
                                                depthMemoryBottom = false;
                                                print(isAspirate);
                                              });
                                            },
                                            decoration: InputDecoration(
                                              border: OutlineInputBorder(),
                                            ),
                                          ),
                                        ),
                                      ),
                                      blueHighlightSpeed(isDispense),
                                    ],
                                  ),
                                ],
                              ),

keypad.dart

class KeyPad extends StatelessWidget
{

  KeyPad({
    required this.onTextInput,
    required this.onBackspace,
  });

  final double width = 275;
  final double height = 90;

  final ValueSetter<String> onTextInput;
  final VoidCallback onBackspace;

  void _textInputHandler(String text) => onTextInput.call(text);

  void _backspaceHandler() => onBackspace.call();

  Container buildRowOne()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '7',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '8',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '9',
            onTextInput: _textInputHandler,
          ),

        ],
      ),
    );
  }

  Container buildRowTwo()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '4',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '5',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '6',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Container buildRowThree()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          TextKey(
            text: '1',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '2',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '3',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Container buildRowFour()
  {
    return Container(
      width: width,
      height: height,
      child: Row(
        children: [
          BackspaceKey(
            onBackspace: _backspaceHandler,
          ),
          TextKey(
            text: '0',
            onTextInput: _textInputHandler,
          ),
          TextKey(
            text: '.',
            onTextInput: _textInputHandler,
          ),
        ],
      ),
    );
  }

  Padding buildRowFive()
  {
    return Padding(
      padding: const EdgeInsets.only(top: 35),
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Color.fromRGBO(92, 103, 148, 1)),
              borderRadius: BorderRadius.circular(45.0),
        ),
        width: 175,
        height: 60,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            IconButton(
              icon: Image.asset('assets/text_key/done.png'),
              onPressed: () {},
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context)
  {
    return SafeArea(
      child: Container(
        child: Column(
          children: [
            buildRowOne(),
            buildRowTwo(),
            buildRowThree(),
            buildRowFour(),
            buildRowFive(),
          ],
        ),
      ),
    );
  }
}


问:
Allow slash & æ,ø,å in preg_match
As the title says, I simply need to allow a normal slash in preg_match. I thought it was something like / or something. But that doesn't work.

I also need to allow european letters: æ,ø,å. How is this done?

Could someone tell me this? :-)

Example

```<code>if(preg_match("/^[a-zA-Z -]+$/", $_POST["last_name"]) == 0)
                {
                    $errMsg = "Dit efternavn må kun indeholde bogstaver, mellemrum og bindestreg.<br>";
                }
</code>```

And then I'm doing a
if(count($errMsg)==0){
 }

Thanks in advance.

答: Put æøå in your regex to match those characters. To match a slash simply escape it with a single backslash. </p>

ContentLicense: CC BY-SA 3.0

Title: Allow slash & æ,ø,å in preg_match

Body:
As the title says, I simply need to allow a normal slash in preg_match. I thought it was something like / or something. But that doesn't work.

I also need to allow european letters: æ,ø,å. How is this done?

Could someone tell me this? :-)

Example

if(preg_match("/^[a-zA-Z -]+$/", $_POST["last_name"]) == 0)
                {
                    $errMsg = "Dit efternavn må kun indeholde bogstaver, mellemrum og bindestreg.
";
                }

And then I'm doing a
if(count($errMsg)==0){
 }

Thanks in advance.


问:
PyCharm node.js does not exists although it is installed in Path (Windows)
I have installed Node.js and it works fine when I run it from the command line on all paths. I ran npm version on the cmd and it worked fine.

But when I run the same npm version in PyCharm it says it doesn't exists although it is in the system's Path...

```<code>'npm' is not recognized as an internal or external command, operable program or batch file.
</code>```

The same things happens when I try to run Node.js cmd subproccess command...

```<code>'tr' is not recognized as an internal or external command,
</code>```

I think it comes from the same problem that Node.js doesn't exists on PyCharm.

答:
File > Settings....

Check the Node.js configuration is correct like the flowing:

Note: Install the node.js extension firstly  (Or search the extension from IDE settings > plugins)

Body:
I have installed Node.js and it works fine when I run it from the command line on all paths. I ran npm version on the cmd and it worked fine.

But when I run the same npm version in PyCharm it says it doesn't exists although it is in the system's Path...

'npm' is not recognized as an internal or external command, operable program or batch file.

The same things happens when I try to run Node.js cmd subproccess command...

'tr' is not recognized as an internal or external command,

I think it comes from the same problem that Node.js doesn't exists on PyCharm.


问:
What does A=B (B [:,])*! mean in Cincom Smalltalk
I'm new to Smalltalk and now using Antlr to parse Cincom Smalltalk code.  There is only a very short piece of code within  and , but I couldn't parse it and couldn't find the related rules.  Could anyone explain to me what this code means?

```<code>mbs = mbGroup (mbGroup [:,])*!
</code>```

If you could further share the related parsing rule, that would be the best.

答: This code is not syntactically legal Smalltalk code, therefore the question what its semantics are is non-sensical. It has no meaning in Smalltalk because it is not Smalltalk.</p>

Body:
I'm new to Smalltalk and now using Antlr to parse Cincom Smalltalk code.  There is only a very short piece of code within  and , but I couldn't parse it and couldn't find the related rules.  Could anyone explain to me what this code means?

mbs = mbGroup (mbGroup [:,])*!

If you could further share the related parsing rule, that would be the best.


问:
Click to Download .ICS File
In my React project, I have a calendar .ics file in my local folders and want the user to download once they click a button so I'm providing the path to the .ics file in that button. However, I'm getting this error:

"Module parse failed: Unexpected token (4:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."

How do I simply have users click a button to download an .ics file?

答:
Introduction

I was going to just add a comment to your answer, since I don't have a definitive answer for your question, but it turns out that I need a minimum of 50 reputation, so...

I'm not sure if provided enough information for your problem, but I'll answer based on what could understand from your statements.

The Problem

[...] However, I'm getting this error:

"Module parse failed: Unexpected token (4:6) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."

I don't know what module bundler your are using, but it seems that your bundler can't recognize .ics files. Hence, you need to declare the type of file. Check your module bundler configuration files and add the required support to the aforesaid extension. If you're using Webpack, for example, change the rules attribute of your webpack.config document adding a new rule, notice that, in this case, you'll need to provide a loader.

I hope this helps. This is my first answer here on StackOverflow, sorry if I misunderstood anything or something simillar.

Title: Click to Download .ICS File


问:
Failed to start bean 'webServerStartStop'; Unable to start embedded Tomcat server - spring-boot-starter-web
Spring application using Maven including only Spring Web dependency gives "Unable to start embedded Tomcat serve" error.

The same project runs on other computers like expected.

Spring Boot Version: 2.4.3

Package Type: JAR

Java Version: 11

No additional code added from the starter project except to print to the console for testing.

Application runs and prints to the console like expected when tomcat is excluded int the pom.xml.

Tested multiple ports.

Tested JDK 8 and 11.

pom.xml dependancies:

```<code>    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</code>```

Log:

```<code>2021-02-22 16:17:28.896  INFO 34556 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 11.0.10 on Soul with PID 34556 (C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo\target\classes started by ryne0 in C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo)
2021-02-22 16:17:28.900  INFO 34556 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-02-22 16:17:28.902 DEBUG 34556 --- [           main] o.s.boot.SpringApplication               : Loading source class com.example.demo.DemoApplication
2021-02-22 16:17:28.995 DEBUG 34556 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@457c9034
2021-02-22 16:17:30.317 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2021-02-22 16:17:30.353  INFO 34556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 81 (http)
2021-02-22 16:17:30.374  INFO 34556 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-22 16:17:30.387  INFO 34556 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-22 16:17:30.507  INFO 34556 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-22 16:17:30.507 DEBUG 34556 --- [           main] w.s.c.ServletWebServerApplicationContext : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2021-02-22 16:17:30.508  INFO 34556 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1513 ms
2021-02-22 16:17:30.535 DEBUG 34556 --- [           main] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
2021-02-22 16:17:30.547 DEBUG 34556 --- [           main] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2021-02-22 16:17:30.599 DEBUG 34556 --- [           main] o.s.b.w.s.f.OrderedRequestContextFilter  : Filter 'requestContextFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [           main] s.b.w.s.f.OrderedCharacterEncodingFilter : Filter 'characterEncodingFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [           main] o.s.b.w.s.f.OrderedFormContentFilter     : Filter 'formContentFilter' configured for use
2021-02-22 16:17:30.817  INFO 34556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:30.828 DEBUG 34556 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2021-02-22 16:17:30.949 DEBUG 34556 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2021-02-22 16:17:30.991 DEBUG 34556 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2021-02-22 16:17:31.003 DEBUG 34556 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2021-02-22 16:17:31.104  WARN 34556 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-02-22 16:17:31.110  INFO 34556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:31.122  INFO 34556 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-02-22 16:17:31.197 DEBUG 34556 --- [           main] ConditionEvaluationReportLoggingListener :

2021-02-22 16:17:32.117 ERROR 34556 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.4.jar:5.3.4]
        at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:934) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:585) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
        at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.4.jar:5.3.4]
        ... 15 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:244) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.4.3.jar:2.4.3]
        ... 17 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:240) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        ... 19 common frames omitted
Caused by: java.io.IOException: Unable to establish loopback connection
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:94) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:61) ~[na:na]
        at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl.<init>(PipeImpl.java:171) ~[na:na]
        at java.base/sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:50) ~[na:na]
        at java.base/java.nio.channels.Pipe.open(Pipe.java:155) ~[na:na]
        at java.base/sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:142) ~[na:na]
        at java.base/sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:44) ~[na:na]
        at java.base/java.nio.channels.Selector.open(Selector.java:295) ~[na:na]
        at org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector(NioSelectorPool.java:52) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.NioSelectorPool.close(NioSelectorPool.java:119) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:386) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1198) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1279) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:608) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1071) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        ... 21 common frames omitted
Caused by: java.net.BindException: Cannot assign requested address: connect
        at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.connect(Net.java:476) ~[na:na]
        at java.base/sun.nio.ch.Net.connect(Net.java:468) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:694) ~[na:na]
        at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:194) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:127) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:76) ~[na:na]
        ... 36 common frames omitted
</code>```

答: Disable the Gamingservices service or go to the task manager and end the task of gamingservices and run again the application. or restart the computer.

Body:
Spring application using Maven including only Spring Web dependency gives "Unable to start embedded Tomcat serve" error.

The same project runs on other computers like expected.

Spring Boot Version: 2.4.3

Package Type: JAR

Java Version: 11

No additional code added from the starter project except to print to the console for testing.

Application runs and prints to the console like expected when tomcat is excluded int the pom.xml.

Tested multiple ports.

Tested JDK 8 and 11.

pom.xml dependancies:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

Log:

2021-02-22 16:17:28.896  INFO 34556 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 11.0.10 on Soul with PID 34556 (C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo\target\classes started by ryne0 in C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo)
2021-02-22 16:17:28.900  INFO 34556 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-02-22 16:17:28.902 DEBUG 34556 --- [           main] o.s.boot.SpringApplication               : Loading source class com.example.demo.DemoApplication
2021-02-22 16:17:28.995 DEBUG 34556 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@457c9034
2021-02-22 16:17:30.317 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [           main] .s.b.w.e.t.TomcatServletWebServerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2021-02-22 16:17:30.353  INFO 34556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 81 (http)
2021-02-22 16:17:30.374  INFO 34556 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-22 16:17:30.387  INFO 34556 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-22 16:17:30.507  INFO 34556 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-22 16:17:30.507 DEBUG 34556 --- [           main] w.s.c.ServletWebServerApplicationContext : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2021-02-22 16:17:30.508  INFO 34556 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1513 ms
2021-02-22 16:17:30.535 DEBUG 34556 --- [           main] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
2021-02-22 16:17:30.547 DEBUG 34556 --- [           main] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2021-02-22 16:17:30.599 DEBUG 34556 --- [           main] o.s.b.w.s.f.OrderedRequestContextFilter  : Filter 'requestContextFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [           main] s.b.w.s.f.OrderedCharacterEncodingFilter : Filter 'characterEncodingFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [           main] o.s.b.w.s.f.OrderedFormContentFilter     : Filter 'formContentFilter' configured for use
2021-02-22 16:17:30.817  INFO 34556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:30.828 DEBUG 34556 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2021-02-22 16:17:30.949 DEBUG 34556 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2021-02-22 16:17:30.991 DEBUG 34556 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2021-02-22 16:17:31.003 DEBUG 34556 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2021-02-22 16:17:31.104  WARN 34556 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-02-22 16:17:31.110  INFO 34556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:31.122  INFO 34556 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-02-22 16:17:31.197 DEBUG 34556 --- [           main] ConditionEvaluationReportLoggingListener :

2021-02-22 16:17:32.117 ERROR 34556 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.4.jar:5.3.4]
        at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:934) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:585) ~[spring-context-5.3.4.jar:5.3.4]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
        at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.4.jar:5.3.4]
        ... 15 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:244) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.4.3.jar:2.4.3]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.4.3.jar:2.4.3]
        ... 17 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:240) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        ... 19 common frames omitted
Caused by: java.io.IOException: Unable to establish loopback connection
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:94) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:61) ~[na:na]
        at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl.<init>(PipeImpl.java:171) ~[na:na]
        at java.base/sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:50) ~[na:na]
        at java.base/java.nio.channels.Pipe.open(Pipe.java:155) ~[na:na]
        at java.base/sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:142) ~[na:na]
        at java.base/sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:44) ~[na:na]
        at java.base/java.nio.channels.Selector.open(Selector.java:295) ~[na:na]
        at org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector(NioSelectorPool.java:52) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.NioSelectorPool.close(NioSelectorPool.java:119) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:386) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1198) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1279) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:608) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1071) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
        ... 21 common frames omitted
Caused by: java.net.BindException: Cannot assign requested address: connect
        at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.connect(Net.java:476) ~[na:na]
        at java.base/sun.nio.ch.Net.connect(Net.java:468) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:694) ~[na:na]
        at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:194) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:127) ~[na:na]
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:76) ~[na:na]
        ... 36 common frames omitted