问:
Clicking a button by selenium
I'm trying to click that button, I've tried several ways and I couldn't.</p>
```<code><div class="item" data-id="rota_grupo">
   <i class="fal fa-users">
   </i>
</div>
</code>```

答:
You can add your chromedriver path to "DRIVER_PATH" and it should work.</p>
```<code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

CHROMEDRIVER_PATH = Service("DRIVER_PATH")

driver = webdriver.Chrome(service=CHROMEDRIVER_PATH)

button = driver.find_element(By.CLASS_NAME, "fa-users")
button.click()

</code>```

Title: Clicking a button by selenium

Body:
You can add your chromedriver path to "DRIVER_PATH" and it should work.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

CHROMEDRIVER_PATH = Service("DRIVER_PATH")

driver = webdriver.Chrome(service=CHROMEDRIVER_PATH)

button = driver.find_element(By.CLASS_NAME, "fa-users")
button.click()


来源: stackexchange

问:
Changing table hline options in R with gt
I am using the gt package to create tables. According the the documentation (see here) there are table options to adjust hline details (e.g., table_body.hlines.style, table_body.hlines.width, etc.). The problem is that there are no value options provided. What are the potential style types to which table_body.hlines.style can be set? I have searched both the gt documentation (which is vast) and on forums but can find no answers.

Edit: I am outputting the table to a .tex file via gtsave, if that matters.

答:
In gt(), the line style the options are "solid" (the default), "dashed", or "dotted".

Weight is given in pixels. The default is 1 pixel.

The color can be defined with a color name or with a hexadecimal color code. The default is "#000000" (black).

ContentLicense: CC BY-SA 4.0


问:
How to run the server when the files are in different folders?
My project is split into 2 folders client and server

How can I run the script through npm start to run both the backend and the frontend at the same time

Screenshot given below:
Two Folders in my project

Client Folder Files

Server Folder Files

Please help me how to run the complete project

答:
You should try to run it on different ports. For example, run the client on port 3000 and the server on port 3001.

you can look here.


问:
How can I search for multiple items in a "any" function: haskell
Right now I have this piece of code\

```<code>filter (any (=='a')) [String]
-- [String] is just any string list
</code>```

if you can't tell this just filters for anything in the string containing 'a'. what I want to know is how can I search for multiple characters? if I try making a string/[char] then I get an error because of the inputs that the any function takes. How can I get around this, because for my purposes I will always have a unknown amount of chars, so I need a way to feed multiple characters into this function. Thank you.

答:
You can use elem to check if something is an element of a list.

```<code>filter (`elem` ['a','e','i','o','u']) "hello world!"
-- or
filter (`elem` "aeiou") "hello world!"
</code>```

This is equivalent to using an explicit lambda:

```<code>filter
   (\x -> x=='a' || x=='e' || x=='i' || x=='o' || x=='u')
   "hello world!"
</code>```

Body:
Right now I have this piece of code\

filter (any (=='a')) [String]
-- [String] is just any string list

if you can't tell this just filters for anything in the string containing 'a'. what I want to know is how can I search for multiple characters? if I try making a string/[char] then I get an error because of the inputs that the any function takes. How can I get around this, because for my purposes I will always have a unknown amount of chars, so I need a way to feed multiple characters into this function. Thank you.

Body:
You can use elem to check if something is an element of a list.

filter (`elem` ['a','e','i','o','u']) "hello world!"
-- or
filter (`elem` "aeiou") "hello world!"

This is equivalent to using an explicit lambda:

filter
   (\x -> x=='a' || x=='e' || x=='i' || x=='o' || x=='u')
   "hello world!"


问:
Can't run docker container in different user
I have 2 users on my ubuntu: personal and work. I created a docker image to run firefox in a container. To make things simple I added an alias in my .bash_aliases file to run it by typing "firefox" in terminal like so:

```<code>docker run --rm -d --name firefox \
-v $XDG_RUNTIME_DIR/pulse:$XDG_RUNTIME_DIR/pulse \
-e PULSE_SERVER=$XDG_RUNTIME_DIR/pulse/native \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
--network host \
shallowduck/firefox:1.0
</code>```

The problem is that firefox does not launch when I'm logged in as "work" user, only "personal".

When I run the command I get container id as output in terminal but nothing launches.

When I run docker ps, the container isn't there.

When I run docker ps -a, there is no trace that the container exited with an error or whatever.

Both users are part of the docker group.

I'm not sure what I'm missing. Any ideas would be appreciated.

答:
I fixed this by running this command in terminal:

```<code>xhost +
</code>```

This adds host names on the list of machines that can connect to X server. I forgot I had to run this command for each user.

Body:
I have 2 users on my ubuntu: personal and work. I created a docker image to run firefox in a container. To make things simple I added an alias in my .bash_aliases file to run it by typing "firefox" in terminal like so:

docker run --rm -d --name firefox \
-v $XDG_RUNTIME_DIR/pulse:$XDG_RUNTIME_DIR/pulse \
-e PULSE_SERVER=$XDG_RUNTIME_DIR/pulse/native \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
--network host \
shallowduck/firefox:1.0

The problem is that firefox does not launch when I'm logged in as "work" user, only "personal".

When I run the command I get container id as output in terminal but nothing launches.

When I run docker ps, the container isn't there.

When I run docker ps -a, there is no trace that the container exited with an error or whatever.

Both users are part of the docker group.

I'm not sure what I'm missing. Any ideas would be appreciated.

Body:
I fixed this by running this command in terminal:

xhost +

This adds host names on the list of machines that can connect to X server. I forgot I had to run this command for each user.


问:
Problem with bundler using rails (mac user)
when i try to run my app, i get this errors:

```<code>Could not find racc-1.5.2 in any of the sources
Run `bundle install` to install missing gems.
</code>```

I run:

```<code>$ bundle install
</code>```

response:

```<code>Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install
</code>```

$ type password two times (system ask twice)

response:

```<code>Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/gems/racc-1.5.2/ext/racc/cparse
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1sxj4i7.rb extconf.rb
checking for rb_ary_subseq()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.
You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'
    from extconf.rb:6:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/extensions/universal-darwin-20/2.6.0/racc-1.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/gems/racc-1.5.2 for inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/extensions/universal-darwin-20/2.6.0/racc-1.5.2/gem_make.out

An error occurred while installing racc (1.5.2), and Bundler cannot continue.
Make sure that `gem install racc -v '1.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 6.1.3, which depends on
    actioncable was resolved to 6.1.3, which depends on
      actionpack was resolved to 6.1.3, which depends on
        actionview was resolved to 6.1.3, which depends on
          rails-dom-testing was resolved to 2.0.3, which depends on
            nokogiri was resolved to 1.11.1, which depends on
              racc

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/gems/nio4r-2.5.5/ext/nio4r
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1yywys0.rb extconf.rb
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
    from extconf.rb:15:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/extensions/universal-darwin-20/2.6.0/nio4r-2.5.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/gems/nio4r-2.5.5 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/extensions/universal-darwin-20/2.6.0/nio4r-2.5.5/gem_make.out

An error occurred while installing nio4r (2.5.5), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.5' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 6.1.3, which depends on
    actioncable was resolved to 6.1.3, which depends on
      nio4r

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1xu8ddx.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `bcrypt_ext.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/extensions/universal-darwin-20/2.6.0/bcrypt-3.1.16/gem_make.out

An error occurred while installing bcrypt (3.1.16), and Bundler cannot continue.
Make sure that `gem install bcrypt -v '3.1.16' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  devise was resolved to 4.7.3, which depends on
    bcrypt

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1k62vcs.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `cruby.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/extensions/universal-darwin-20/2.6.0/bindex-0.8.1/gem_make.out

An error occurred while installing bindex (0.8.1), and Bundler cannot continue.
Make sure that `gem install bindex -v '0.8.1' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  web-console was resolved to 4.1.0, which depends on
    bindex

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/gems/msgpack-1.4.2/ext/msgpack
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-5tsgu7.rb extconf.rb
checking for ruby/st.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
    from extconf.rb:3:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/extensions/universal-darwin-20/2.6.0/msgpack-1.4.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/gems/msgpack-1.4.2 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/extensions/universal-darwin-20/2.6.0/msgpack-1.4.2/gem_make.out

An error occurred while installing msgpack (1.4.2), and Bundler cannot continue.
Make sure that `gem install msgpack -v '1.4.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  bootsnap was resolved to 1.7.2, which depends on
    msgpack

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-18f31t0.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `breakpoint.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/extensions/universal-darwin-20/2.6.0/byebug-11.1.3/gem_make.out

An error occurred while installing byebug (11.1.3), and Bundler cannot continue.
Make sure that `gem install byebug -v '11.1.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  byebug
</code>```

Info:

```<code>ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
</code>```

Bundler version 2.2.12 (2021-03-01 commit 1de3f8de73)(this is when i start having problems)

```<code>rails -v
Rails 6.1.3
</code>```

答: Make sure you've granted developer tools access to Terminal, without it no matter how many times you do xcode-select --install it won't work

Body:
when i try to run my app, i get this errors:

Could not find racc-1.5.2 in any of the sources
Run `bundle install` to install missing gems.

I run:

$ bundle install

response:

Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install

$ type password two times (system ask twice)

response:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/gems/racc-1.5.2/ext/racc/cparse
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1sxj4i7.rb extconf.rb
checking for rb_ary_subseq()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.
You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'
    from extconf.rb:6:in `'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/extensions/universal-darwin-20/2.6.0/racc-1.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/gems/racc-1.5.2 for inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-861puoracc-1.5.2/extensions/universal-darwin-20/2.6.0/racc-1.5.2/gem_make.out

An error occurred while installing racc (1.5.2), and Bundler cannot continue.
Make sure that `gem install racc -v '1.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 6.1.3, which depends on
    actioncable was resolved to 6.1.3, which depends on
      actionpack was resolved to 6.1.3, which depends on
        actionview was resolved to 6.1.3, which depends on
          rails-dom-testing was resolved to 2.0.3, which depends on
            nokogiri was resolved to 1.11.1, which depends on
              racc

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/gems/nio4r-2.5.5/ext/nio4r
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1yywys0.rb extconf.rb
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
    from extconf.rb:15:in `'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/extensions/universal-darwin-20/2.6.0/nio4r-2.5.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/gems/nio4r-2.5.5 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-5s57nvnio4r-2.5.5/extensions/universal-darwin-20/2.6.0/nio4r-2.5.5/gem_make.out

An error occurred while installing nio4r (2.5.5), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.5' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 6.1.3, which depends on
    actioncable was resolved to 6.1.3, which depends on
      nio4r

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1xu8ddx.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16/ext/mri
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `bcrypt_ext.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/gems/bcrypt-3.1.16 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-4k1ekzbcrypt-3.1.16/extensions/universal-darwin-20/2.6.0/bcrypt-3.1.16/gem_make.out

An error occurred while installing bcrypt (3.1.16), and Bundler cannot continue.
Make sure that `gem install bcrypt -v '3.1.16' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  devise was resolved to 4.7.3, which depends on
    bcrypt

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-1k62vcs.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1/ext/skiptrace
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `cruby.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/gems/bindex-0.8.1 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-z8an9bbindex-0.8.1/extensions/universal-darwin-20/2.6.0/bindex-0.8.1/gem_make.out

An error occurred while installing bindex (0.8.1), and Bundler cannot continue.
Make sure that `gem install bindex -v '0.8.1' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  web-console was resolved to 4.1.0, which depends on
    bindex

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/gems/msgpack-1.4.2/ext/msgpack
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-5tsgu7.rb extconf.rb
checking for ruby/st.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
    from extconf.rb:3:in `'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/extensions/universal-darwin-20/2.6.0/msgpack-1.4.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/gems/msgpack-1.4.2 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-tk45tbmsgpack-1.4.2/extensions/universal-darwin-20/2.6.0/msgpack-1.4.2/gem_make.out

An error occurred while installing msgpack (1.4.2), and Bundler cannot continue.
Make sure that `gem install msgpack -v '1.4.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  bootsnap was resolved to 1.7.2, which depends on
    msgpack

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210303-5388-18f31t0.rb extconf.rb
creating Makefile

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
make DESTDIR\= clean

current directory: /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3/ext/byebug
make DESTDIR\=
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20/ruby/config.h',
needed by `breakpoint.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/gems/byebug-11.1.3 for
inspection.
Results logged to
/var/folders/_b/7g9qk9qn2tbc7m16nsnj7jww0000gn/T/bundler20210303-5388-pjciubbyebug-11.1.3/extensions/universal-darwin-20/2.6.0/byebug-11.1.3/gem_make.out

An error occurred while installing byebug (11.1.3), and Bundler cannot continue.
Make sure that `gem install byebug -v '11.1.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  byebug

Info:

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

Bundler version 2.2.12 (2021-03-01 commit 1de3f8de73)(this is when i start having problems)

rails -v
Rails 6.1.3


问:
Facebook Graph API error - Unknown path components
My function to list add_group_account id of a particular user ends up by receiving the following error.

```<code>Message: Unknown path components: /adaccountgroups
</code>```

I'm following this guideline Facebook API documentation

```<code>public function tp()
{

    $fb = new Facebook([
      'app_id' => "621201298943758",
      'app_secret' => "f0aa4ae743ef.................",
      'default_graph_version' => 'v2.5',
      'default_access_token' => "EAAI0ZBrLB7w4BAIUyoGjSB50ZBsXbPxYfCjk6WxPQIa.................................",
     ]);

    try {
          // Returns a `Facebook\FacebookResponse` object
          $response = $fb->get(
            '/me/adaccountgroups',
            'EAAI0ZBrLB7w4BAIUyoGjSB50ZBs.....................'
          );
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
          echo 'Graph returned an error: ' . $e->getMessage();
          exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
          echo 'Facebook SDK returned an error: ' . $e->getMessage();
          exit;
        }
        $graphNode = $response->getGraphNode();

}
</code>```

答:
As I have discovered there is no endpoint or function by the name "adaccountgroups"available even though it was mentioned in their own documentation.

To get the add account ID corresponding to a particular user account it has to be called in following pattern

curl

```<code>https://graph.facebook.com/v13.0/me/adaccounts?access_token=EAAI0ZBrLB7w...............
</code>```

SDK

```<code>$response = $fb->get(
            '/me/adaccounts',
            '{token.....}'
          );
</code>```

Body:
My function to list add_group_account id of a particular user ends up by receiving the following error.

Message: Unknown path components: /adaccountgroups

I'm following this guideline Facebook API documentation

public function tp()
{

    $fb = new Facebook([
      'app_id' => "621201298943758",
      'app_secret' => "f0aa4ae743ef.................",
      'default_graph_version' => 'v2.5',
      'default_access_token' => "EAAI0ZBrLB7w4BAIUyoGjSB50ZBsXbPxYfCjk6WxPQIa.................................",
     ]);

    try {
          // Returns a `Facebook\FacebookResponse` object
          $response = $fb->get(
            '/me/adaccountgroups',
            'EAAI0ZBrLB7w4BAIUyoGjSB50ZBs.....................'
          );
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
          echo 'Graph returned an error: ' . $e->getMessage();
          exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
          echo 'Facebook SDK returned an error: ' . $e->getMessage();
          exit;
        }
        $graphNode = $response->getGraphNode();

}

Body:
As I have discovered there is no endpoint or function by the name "adaccountgroups"available even though it was mentioned in their own documentation.

To get the add account ID corresponding to a particular user account it has to be called in following pattern

curl

https://graph.facebook.com/v13.0/me/adaccounts?access_token=EAAI0ZBrLB7w...............

SDK

$response = $fb->get(
            '/me/adaccounts',
            '{token.....}'
          );


问:
Why is the size not a template argument of std::initializer_list?
std::initializer_list is constructed by the compiler from a brace-enclosed init list and the size of this list must be a compile time constant.

So why did the committee decide to omit the size from the template arguments? This possibly prevents some optimizations and makes some things impossible (initializing std::array from a std::initializer_list).

答: One upside of the existing system is that you can export functions which take an initializer_list from a DLL. If it were templated on the size, they would have to be shipped as source.

ContentLicense: CC BY-SA 3.0


问:
How to do perform a performance testing, keycloak enable web application
i need example for this.can anyone to do demonstrate it.with all steps. i try to lot of methods.but any methods not work properly.
Sample Screenshot

答:
We cannot do demonstrate it.with all steps looking into single screenshot with View Results Tree listener limited output.

Moreover, keycloak can be configured differently hence "all steps" may be different for OpenID Connect and SAML

In general you need to correlate dynamic parameters like execution, tab_id, session_code, etc. using a suitable JMeter Post-Processor like Regular Expression Extractor or Boundary Extractor, store them into JMeter Variables and replace recorded values with the JMeter Variables.

Example dynamic parameters detection:

And handling:


问:
How does spring create and update databases?
I've seen this line of code

```<code>spring.jpa.hibernate.ddl-auto=none
</code>```

in multiple spring tutorials. My question is for example in a production scenario I want my app to create a database for the first time in the client machine then keep using the database and not keep recreating a new database each time it is run. How can I achieve this? and what does the above code really mean?

答:
To achive this you dont have to do anything. Just inside the application.properties file add:

```<code>spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=password
</code>```

The rest is handled by JPA.

Sometimes we may need to run our own sql scripts on application's startup by using data.sql or schema.sql files. In this situation we have to disable Hibernate automatic schema creation by adding the following inside the application.properties file.

```<code>spring.jpa.hibernate.ddl-auto=none
</code>```

Body:
I've seen this line of code

spring.jpa.hibernate.ddl-auto=none

in multiple spring tutorials. My question is for example in a production scenario I want my app to create a database for the first time in the client machine then keep using the database and not keep recreating a new database each time it is run. How can I achieve this? and what does the above code really mean?

Body:
To achive this you dont have to do anything. Just inside the application.properties file add:

spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=password

The rest is handled by JPA.

Sometimes we may need to run our own sql scripts on application's startup by using data.sql or schema.sql files. In this situation we have to disable Hibernate automatic schema creation by adding the following inside the application.properties file.

spring.jpa.hibernate.ddl-auto=none


问:
Code execution on iOS, using background audio
First of all, I have to say that I am not interested in publishing in the appstore, but at the same time I am not interested in jailbreaking my phone.

I want to experiment with code execution in the background, so I'd like to write a simple application that periodically logs my battery level and my position, let's say every 10 minutes. I don't want to schedule local notifications, so to my understanding, this would only be possible (?) going the 'Pastebot way'.

Can someone please give me more information about that? If I want to test it, will I have to schedule a timer and properly configure my audio session? Or, in other words, I don't understand where my "background executing code" should be placed. Any help/information highly appreciated!

答: If you want to use location services, than you can set your application background mode in app info.plist (UIBackgroundModes and add to it location item). And in your application start monitoring location change. Thats it, your application won't be suspended (till system will be in heavy position with memory for other process).


问:
How to filter single string using JSONPath?
I have the following JSON Structure:

```<code>    [
        { "category": "reference",
          "author": "Nigel Rees",
          "title": "Sayings of the Century",
          "price": 8.95
        },
        { "category": "fiction",
          "author": "Evelyn Waugh",
          "title": "Sword of Honour",
          "price": 12.99
        },
        { "category": "fiction",
          "author": "Herman Melville",
          "title": "Moby Dick",
          "isbn": "0-553-21311-3",
          "price": 8.99
        },
        { "category": "fiction",
          "author": "J. R. R. Tolkien",
          "title": "The Lord of the Rings",
          "isbn": "0-395-19395-8",
          "price": 22.99
        }
    ]
</code>```

I want to get only ONE object that containts the title "The Lord of the Rings"

If i type:

$.[*].title

The output it gives me is:

```<code>[
 "Sayings of the Century",
 "Sword of Honour",
 "Moby Dick",
 "The Lord of the Rings"
]
</code>```

I tried doing this:

$.[*].[?(@.title=='The Lord of the Rings')]

But it did'nt work.
Please, can someone help me?

Thanks in advance!

答:
Excuse my previous answer. I didn't know jsonpath was a thing. I found your answer:

```<code>$[?(@.title == 'The Lord of the Rings')]
</code>```

The reason is because, since the objects are in the root element, you are already trying to select the title in the elements with the @.title. When you select all elements with $.[*], you're already too low of a level to find by title.

Body:
I have the following JSON Structure:

    [
        { "category": "reference",
          "author": "Nigel Rees",
          "title": "Sayings of the Century",
          "price": 8.95
        },
        { "category": "fiction",
          "author": "Evelyn Waugh",
          "title": "Sword of Honour",
          "price": 12.99
        },
        { "category": "fiction",
          "author": "Herman Melville",
          "title": "Moby Dick",
          "isbn": "0-553-21311-3",
          "price": 8.99
        },
        { "category": "fiction",
          "author": "J. R. R. Tolkien",
          "title": "The Lord of the Rings",
          "isbn": "0-395-19395-8",
          "price": 22.99
        }
    ]

I want to get only ONE object that containts the title "The Lord of the Rings"

If i type:

$.[*].title

The output it gives me is:

[
 "Sayings of the Century",
 "Sword of Honour",
 "Moby Dick",
 "The Lord of the Rings"
]

I tried doing this:

$.[*].[?(@.title=='The Lord of the Rings')]

But it did'nt work.
Please, can someone help me?

Thanks in advance!

Body:
Excuse my previous answer. I didn't know jsonpath was a thing. I found your answer:

$[?(@.title == 'The Lord of the Rings')]

The reason is because, since the objects are in the root element, you are already trying to select the title in the elements with the @.title. When you select all elements with $.[*], you're already too low of a level to find by title.


问:
Dictionary KEYS python
```<code>

for key in Roles_dict1.keys:

</code>```

Thanks in Advance

答: Should be Roles_dict1.keys() rather than Roles_dict1.keys.

Title: Dictionary KEYS python

Body:
for key in Roles_dict1.keys:

Thanks in Advance


问:
Laravel queue processed event listener doesn't contain my user
I'm using the Laravel 8 job and queue system. I'm dispatching a job called FetchBeamData within one of my controllers and am passing it the currently logged in user.

Then, inside of my AppServiceProvider I'm using the JobProcessed event that will trigger some custom functionality.

But when I unserialize my payload, I'm not seeing my user at all in there, what am I missing?

My user is passed into my job's constructor as an optional argument:

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($beam, $user = null)
{
    $this->beam = $beam;
    $this->user = $user;
}
```
<p>And when I dispatch the job, I run:</p>
<pre class="lang-php prettyprint-override"><code>FetchBeamData::dispatch($beam, Auth::user());
</code>```

Inside of my listener, I expect to see the user in there:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Queue::after(function (JobProcessed $event) {
        $payload = $event->job->payload();

        Log::debug('=== AFTER ===', [
            'connectionName' => $event->connectionName,
            'job' => $event->job,
            'payload' => unserialize($payload['data']['command'])
        ]);
    });
}
```
<p>What am I missing to access this, the current output is:</p>
<pre class="lang-json prettyprint-override"><code>{
   "connectionName":"database",
   "job":{
      "Illuminate\\Queue\\Jobs\\DatabaseJob":[

      ]
   },
   "payload":{
      "App\\Jobs\\FetchBeamData":{
         "job":null,
         "connection":null,
         "queue":"on-demand-runs-now",
         "chainConnection":null,
         "chainQueue":null,
         "chainCatchCallbacks":null,
         "delay":null,
         "afterCommit":null,
         "middleware":[

         ],
         "chained":[

         ]
      }
   }
}
</code>```

答:
this should do the trick

```<code>public $beam;
public $user;

public function __construct($beam, $user = null)
{
  $this->beam = $beam;
  $this->user = $user;
</code>```

Body:
I'm using the Laravel 8 job and queue system. I'm dispatching a job called FetchBeamData within one of my controllers and am passing it the currently logged in user.

Then, inside of my AppServiceProvider I'm using the JobProcessed event that will trigger some custom functionality.

But when I unserialize my payload, I'm not seeing my user at all in there, what am I missing?

My user is passed into my job's constructor as an optional argument:

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($beam, $user = null)
{
    $this->beam = $beam;
    $this->user = $user;
}

And when I dispatch the job, I run:

FetchBeamData::dispatch($beam, Auth::user());

Inside of my listener, I expect to see the user in there:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Queue::after(function (JobProcessed $event) {
        $payload = $event->job->payload();

        Log::debug('=== AFTER ===', [
            'connectionName' => $event->connectionName,
            'job' => $event->job,
            'payload' => unserialize($payload['data']['command'])
        ]);
    });
}

What am I missing to access this, the current output is:

{
   "connectionName":"database",
   "job":{
      "Illuminate\\Queue\\Jobs\\DatabaseJob":[

      ]
   },
   "payload":{
      "App\\Jobs\\FetchBeamData":{
         "job":null,
         "connection":null,
         "queue":"on-demand-runs-now",
         "chainConnection":null,
         "chainQueue":null,
         "chainCatchCallbacks":null,
         "delay":null,
         "afterCommit":null,
         "middleware":[

         ],
         "chained":[

         ]
      }
   }
}

Body:
this should do the trick

public $beam;
public $user;

public function __construct($beam, $user = null)
{
  $this->beam = $beam;
  $this->user = $user;


问:
How to space the children of a div with css?
I want a gap of say 30px; between all children of my div. E.g if I have:

```<code><div id="parent">
   <img ... />
   <p>...</p>
   <div>.......</div>
</div>
</code>```

I want all of them to have a space of 30px; between them. How can I do this with CSS?

答:
Use CSS gap property.

.parent_class_name{
  gap: 30px;
}
```
<p>The above CSS code will apply a gap/separation of <code>30px</code> between children of the <code>parent_class_name</code> class.</p>
<p>Example: This code will apply <code>1rem</code> gap between element (rows and columns).</p>
<pre class="lang-html prettyprint-override"><code><div class="gap_container">
  <div>a</div>
  <div>b</div>
  <div>c</div>
</div>
</code>```

.gap_container{
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
```

The gap property defines the size of the gap between the rows and columns. It is a shorthand for the following properties:

row-gap

column-gap

Apply row and column values separately.
gap: row-value column-value;

Learn more: w3school

Body:
I want a gap of say 30px; between all children of my div. E.g if I have:

...

.......

I want all of them to have a space of 30px; between them. How can I do this with CSS?

Body:
Use CSS gap property.

.parent_class_name{
  gap: 30px;
}

The above CSS code will apply a gap/separation of 30px between children of the parent_class_name class.

Example: This code will apply 1rem gap between element (rows and columns).

<div class="gap_container">
  <div>a</div>
  <div>b</div>
  <div>c</div>
</div>

.gap_container{
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

The gap property defines the size of the gap between the rows and columns. It is a shorthand for the following properties:

row-gap

column-gap

Apply row and column values separately.
gap: row-value column-value;

Learn more: w3school


问:
How can I use the Spring @Pattern annotation to force the string to comply to one of the regexes, but not all at the same time?
I don't want to have several regexes that all have to be fulfilled. Rather, I would like that only one of the regexes provided are valid, not the others. An example could be that I want a string to fulfill the demands for either an IP on V4 format or V6 format, but not both at the same time.</p>
```<code>@Pattern(regexp = ipV4)
@Pattern(regexp = ipV6)
String ipAddress;
</code>```

答:
A naive solution is to change the regex to match several alternatives:</p>
```<code>@Pattern(regexp = "ipV4|ipV6")
String ipAddress;
</code>```

Body:
I don't want to have several regexes that all have to be fulfilled. Rather, I would like that only one of the regexes provided are valid, not the others. An example could be that I want a string to fulfill the demands for either an IP on V4 format or V6 format, but not both at the same time.

@Pattern(regexp = ipV4)
@Pattern(regexp = ipV6)
String ipAddress;

Body:
A naive solution is to change the regex to match several alternatives:

@Pattern(regexp = "ipV4|ipV6")
String ipAddress;


问:
Failed to load plugin '@typescript-eslint' declared in '.eslintrc': Class extends value undefined is not a constructor or null
https://github.com/calvertwong/typescript-eslint-error-on-start

I am having issue with @typescript-eslint and I am getting an Failed to compile error when executing npm start.

Failed to load plugin '@typescript-eslint' declared in '.eslintrc': Class extends value undefined is not a constructor or null

I have two React typescript projects and they both use the same configuration but one of them is giving me the error. I have provided a github link above, can someone help me out? I have tried downgrading eslint related version but no luck.

答: I have resolved this issue. I believe react-script is using babel-eslint which is deprecated and was giving me trouble but I am not too sure about it. What I did was I execute npm audit fix --force, saw react-script being upgraded from version 4.3 to 5 and the failed to load plugin issue went away.


答:
You should consider, a function like a -> [a] -> Bool because you are searching for a function, which checks for a character in a list.

So the answer is:

```<code>filter (\x -> elem x [1..3]) [1..10]
</code>```

Title: How can I search for multiple items in a "any" function: haskell

Body:
Right now I have this piece of code\

filter (any (=='a')) [String]
-- [String] is just any string list

if you can't tell this just filters for anything in the string containing 'a'. what I want to know is how can I search for multiple characters? if I try making a string/[char] then I get an error because of the inputs that the any function takes. How can I get around this, because for my purposes I will always have a unknown amount of chars, so I need a way to feed multiple characters into this function. Thank you.

Body:
You should consider, a function like a -> [a] -> Bool because you are searching for a function, which checks for a character in a list.

So the answer is:

filter (\x -> elem x [1..3]) [1..10]


问:
[F#][Type inference] - How to improve my program?
I'm currently building a program to type inference in F# using the following AST:

```<code>// errors
//

exception SyntaxError of string * FSharp.Text.Lexing.LexBuffer<char>
exception TypeError of string
exception UnexpectedError of string

let throw_formatted exnf fmt = ksprintf (fun s -> raise (exnf s)) fmt

let unexpected_error fmt = throw_formatted UnexpectedError fmt

// AST type definitions
//

type tyvar = string

type ty =
    | TyName of string //constants
    | TyArrow of ty * ty
    | TyVar of tyvar //'a,'b for example
    | TyTuple of ty list

// pseudo data constructors for literal types
let TyFloat = TyName "float"
let TyInt = TyName "int"
let TyChar = TyName "char"
let TyString = TyName "string"
let TyBool = TyName "bool"
let TyUnit = TyName "unit"

// active pattern for literal types
let private (|TyLit|_|) name = function
    | TyName s when s = name -> Some ()
    | _ -> None

let (|TyFloat|_|) = (|TyLit|_|) "float"
let (|TyInt|_|) = (|TyLit|_|) "int"
let (|TyChar|_|) = (|TyLit|_|) "char"
let (|TyString|_|) = (|TyLit|_|) "string"
let (|TyBool|_|) = (|TyLit|_|) "bool"
let (|TyUnit|_|) = (|TyLit|_|) "unit"

type scheme = Forall of tyvar list * ty

type lit = LInt of int
         | LFloat of float
         | LString of string
         | LChar of char
         | LBool of bool
         | LUnit

type binding = bool * string * ty option * expr    // (is_recursive, id, optional_type_annotation, expression)

and expr =
    | Lit of lit
    | Lambda of string * ty option * expr
    | App of expr * expr
    | Var of string
    | LetIn of binding * expr
    | IfThenElse of expr * expr * expr option
    | Tuple of expr list
    | BinOp of expr * string * expr
    | UnOp of string * expr

let fold_params parms e0 =
 List.foldBack (fun (id, tyo) e -> Lambda (id, tyo, e)) parms e0

let (|Let|_|) = function
    | LetIn ((false, x, tyo, e1), e2) -> Some (x, tyo, e1, e2)
    | _ -> None

let (|LetRec|_|) = function
    | LetIn ((true, x, tyo, e1), e2) -> Some (x, tyo, e1, e2)
    | _ -> None

type 'a env = (string * 'a) list

type value =
    | VLit of lit
    | VTuple of value list
    | Closure of value env * string * expr
    | RecClosure of value env * string * string * expr

type interactive = IExpr of expr | IBinding of binding

// pretty printers
//

// utility function for printing lists by flattening strings with a separator
let rec flatten p sep es =
    match es with
    | [] -> ""
    | [e] -> p e
    | e :: es -> sprintf "%s%s %s" (p e) sep (flatten p sep es)

// print pairs within the given env using p as printer for the elements bound within
let pretty_env p env = sprintf "[%s]" (flatten (fun (x, o) -> sprintf "%s=%s" x (p o)) ";" env)

// print any tuple given a printer p for its elements
let pretty_tupled p l = flatten p ", " l

let rec pretty_ty t =
    match t with
    | TyName s -> s
    | TyArrow (t1, t2) -> sprintf "%s -> %s" (pretty_ty t1) (pretty_ty t2)
    | TyVar n -> sprintf "'%s" n
    | TyTuple ts -> sprintf "(%s)" (pretty_tupled pretty_ty ts)

let pretty_lit lit =
    match lit with
    | LInt n -> sprintf "%d" n
    | LFloat n -> sprintf "%g" n
    | LString s -> sprintf "\"%s\"" s
    | LChar c -> sprintf "%c" c
    | LBool true -> "true"
    | LBool false -> "false"
    | LUnit -> "()"

let rec pretty_expr e =
    match e with
    | Lit lit -> pretty_lit lit

    | Lambda (x, None, e) -> sprintf "fun %s -> %s" x (pretty_expr e)
    | Lambda (x, Some t, e) -> sprintf "fun (%s : %s) -> %s" x (pretty_ty t) (pretty_expr e)

    // TODO pattern-match sub-application cases
    | App (e1, e2) -> sprintf "%s %s" (pretty_expr e1) (pretty_expr e2)

    | Var x -> x

    | Let (x, None, e1, e2) ->
        sprintf "let %s = %s in %s" x (pretty_expr e1) (pretty_expr e2)

    | Let (x, Some t, e1, e2) ->
        sprintf "let %s : %s = %s in %s" x (pretty_ty t) (pretty_expr e1) (pretty_expr e2)

    | LetRec (x, None, e1, e2) ->
        sprintf "let rec %s = %s in %s" x (pretty_expr e1) (pretty_expr e2)

    | LetRec (x, Some tx, e1, e2) ->
        sprintf "let rec %s : %s = %s in %s" x (pretty_ty tx) (pretty_expr e1) (pretty_expr e2)

    | IfThenElse (e1, e2, e3o) ->
        let s = sprintf "if %s then %s" (pretty_expr e1) (pretty_expr e2)
        match e3o with
        | None -> s
        | Some e3 -> sprintf "%s else %s" s (pretty_expr e3)

    | Tuple es ->
        sprintf "(%s)" (pretty_tupled pretty_expr es)

    | BinOp (e1, op, e2) -> sprintf "%s %s %s" (pretty_expr e1) op (pretty_expr e2)

    | UnOp (op, e) -> sprintf "%s %s" op (pretty_expr e)

    | _ -> unexpected_error "pretty_expr: %s" (pretty_expr e)

let rec pretty_value v =
    match v with
    | VLit lit -> pretty_lit lit

    | VTuple vs -> pretty_tupled pretty_value vs

    | Closure (env, x, e) -> sprintf "<|%s;%s;%s|>" (pretty_env pretty_value env) x (pretty_expr e)

    | RecClosure (env, f, x, e) -> sprintf "<|%s;%s;%s;%s|>" (pretty_env pretty_value env) f x (pretty_expr e)
</code>```

and the type inference algorithm is the following:

```<code>let type_error fmt = throw_formatted TypeError fmt

type subst = (tyvar * ty) list

// type inference
//

// starting environment with operation
let gamma0 : scheme env = [
    ("+", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("-", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("*", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("/", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("%", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("=", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<=", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    (">", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("=>", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<>", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("and", Forall([],TyArrow (TyBool, TyArrow (TyBool, TyBool))))
    ("or", Forall([],TyArrow (TyBool, TyArrow (TyBool, TyBool))))
    ("not", Forall([],TyArrow (TyBool, TyBool)))
    ("-", Forall([],TyArrow (TyInt, TyInt)))

    ("+.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("-.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("*.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("/.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("%.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("=.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<=.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    (">.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("=>.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<>.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("-.", Forall([],TyArrow (TyFloat, TyFloat)))
]

let mutable counter = -1

let generate_fresh_variable () =
    counter <- counter + 1
    counter + int 'a'
        |> char
        |> string

let rec occurs (tv : tyvar) (t : ty) : bool =
    match t with
    | TyVar t1 -> tv = t1
    | TyArrow (t1,t2) -> occurs tv t1 || occurs tv t2
    | TyName t1 -> false
    | TyTuple tt -> let rec occ_list (tv : tyvar) (t : ty list) : bool =
                        match t with
                        |[] -> false
                        |head::tail -> if occurs tv head
                                       then true
                                       else occ_list tv tail
                    occ_list tv tt

// TODO implement this
let compose_subst (s1 : subst) (s2 : subst) : subst = s1 @ s2

// TODO implement this
let rec unify (t1 : ty) (t2 : ty) : subst =
    match t1, t2 with
    | TyName n1, TyName n2 -> if n1 <> n2
                              then type_error "unify: unification between different variables name can't be execute"
                              else []
    | TyVar tv, _ -> if occurs tv t2
                     then type_error "unify: unification fails"
                     else [(tv , t2)]

    | _ , TyVar tv -> if occurs tv t1
                      then type_error "unify: unification fails"
                      else [(tv , t1)]

    | TyArrow (tl1,tr1), TyArrow (tl2,tr2) ->   let u1 = unify tl1 tl2
                                                let u2 = unify tr1 tr2
                                                compose_subst u1 u2

                                                (*let subs1 = unify tl1 tl2
                                                let te1 = apply_subst tr1 subs1
                                                let te2 = apply_subst tr2 subs1
                                                let subs2 = unify te1 te2
                                                compose_subst subs1 subs2*)
    | _ -> unexpected_error "unify: unsupported operation"

(* substitute term s for all occurrences of var x in term t *)
let rec subst (s : ty) (x : tyvar) (t : ty) : ty =
  match t with
  | TyVar y -> if x = y then s else t
  | TyArrow (u, v) -> TyArrow (subst s x u, subst s x v)
  | TyName n -> t
  | TyTuple ts -> TyTuple(List.map (subst s x) ts)

// TODO implement this
let apply_subst (t : ty) (s : subst) : ty =
  List.foldBack (fun (x, e) -> subst e x) s t

let apply_subst_helper s t = apply_subst t s

// Give all tyvar in a type -> FV
let rec freevars_ty (t : ty) : tyvar Set =
    match t with
    | TyName _ -> Set.empty
    | TyArrow (t1, t2) -> Set.union (freevars_ty t1) (freevars_ty t2)
    | TyVar tv -> Set.singleton tv
    | TyTuple ts -> List.fold (fun set t -> Set.union set (freevars_ty t)) Set.empty ts

let freevars_scheme (Forall (tvs, t)) =
    Set.difference (freevars_ty t) (Set.ofList tvs)

let rec freevars_env (en: scheme env) : tyvar Set =
    match en with
    | [] -> Set.empty
    | e  -> match e with
            |(_,sc)::tail -> Set.union (freevars_env tail) (freevars_scheme sc)

let generalize (env : scheme env) (typ : ty) : scheme =
    let vars = Set.difference (freevars_ty typ) (freevars_env env)
    Forall (Set.toList vars, typ)

let instantiate (Forall (tvs, typ)) : ty =
    let nvars = List.map (fun _ -> TyVar(generate_fresh_variable()) ) tvs
    let s = Map.ofSeq (Seq.zip tvs nvars) |> Map.toList
    apply_subst typ s

let rec tupleMap l: subst =
    match l with
    |[] -> []
    |head::tail ->
                   match head with
                   |(_,su) -> compose_subst su (tupleMap tail)

let rec tupleMap2 l: ty list =
    match l with
    |[] -> []
    |head::tail ->
                   match head with
                   |(typ,_) -> typ::(tupleMap2 tail)
// type inference
//

let rec typeinfer_expr (env : scheme env) (e : expr) : ty * subst =
    match e with
    | Var x ->
        let _, t = List.find (fun (y, _) -> x = y) env
        (instantiate t, [])

    | Lit (LInt _) -> (TyInt, [])
    | Lit (LFloat _) -> (TyFloat, [])
    | Lit (LString _) -> (TyString, [])
    | Lit (LChar _) -> (TyChar, [])
    | Lit (LBool _) -> (TyBool, [])
    | Lit LUnit -> (TyUnit, [])

    | App (e1, e2) ->
        let codTy = TyVar(generate_fresh_variable ())
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr env e2
        let s3 = unify t1 (TyArrow (t2,codTy))
        let s32 = compose_subst s3 s2
        let s321 = compose_subst s32 s1
        (apply_subst codTy s321, s321)

    | Lambda (x, None, e) ->
        let freshVar = TyVar(generate_fresh_variable())
        let sc1 = Forall(list.Empty,freshVar) //46:00 lesson 30 november
        let t,s = typeinfer_expr((x, sc1) :: env) e
        let finalType = apply_subst (TyArrow(freshVar,t)) s
        (finalType,s)

    | Lambda (x, Some typ, e) ->
        let sc1 = Forall(list.Empty,typ)
        let t,s = typeinfer_expr((x, sc1) :: env) e
        let finalType = apply_subst (TyArrow(typ,t)) s
        (finalType,s)

    //monomorphic version
    (*| Let (x, None , e1, e2) ->
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr ((x,t1) :: env) e2
        let s3 = compose_subst s2 s1
        (t2, s3)*)

    //polimorphic version
    | Let (x, None , e1, e2) ->
        let t1, s1 = typeinfer_expr env e1
        //Generalize
        let sc1 = generalize env t1
        let t2, s2 = typeinfer_expr ((x,sc1) :: env) e2
        let s3 = compose_subst s2 s1
        (t2, s3)

    | IfThenElse (e1, e2, e3o) ->
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr env e2
        let s4 = unify t1 TyBool
        match e3o with
        | None -> let s5 = unify t2 TyUnit
                  let tot = compose_subst (compose_subst (compose_subst s5 s4) s2) s1
                  (apply_subst t2 s5, tot)

        | Some ex -> let t3, s3 = typeinfer_expr env ex
                     let s5 = unify t2 t3
                     let tot = compose_subst (compose_subst (compose_subst (compose_subst s5 s4) s3) s2) s1
                     (apply_subst t2 s5, tot)

    | Tuple es ->
        let t = List.map (typeinfer_expr env) es
        let comp = tupleMap t
        let typL =  tupleMap2 t
        let typ = TyTuple(List.map (apply_subst_helper comp) typL)
        (typ,comp)

    | BinOp(e1, op, e2) ->
        typeinfer_expr env (App (App (Var op, e1), e2))

    | BinOp (_, op, _) -> unexpected_error "typecheck_expr: unsupported binary operator (%s)" op

    | UnOp(op, e) ->
        typeinfer_expr env (App (Var op, e))

    | UnOp (op, _) -> unexpected_error "typeinfer_expr: unsupported unary operator (%s)" op

    | _ -> unexpected_error "typeinfer_expr: unsupported expression: %s [AST: %A]" (pretty_expr e) e
</code>```

I would like to have some explanation on why when I start the program and write inside the shell the following line:

let test = fun x -> x;;

the type returned by the type inference is 'b ->'b and not 'a ->' a.

it's probably because in the process of type inference the function generate_fresh_variable () is called twice for the lamba and for the var, but I would like to understand how I can make it come out as type 'a ->' a?

Obviously I accept suggestions on how to improve the code and how to better implement the algorithm, I apologize for my lack of experience but it is the first time that I look at F # and the type inference.

答:
My guess is that you inferred the type of another expression before this one, which caused the variable counter to increment. For example, consider the following test code:

let test () =
    let lambda = Lambda ("x", None, Var "x")   // fun x -> x
    let ty, subs = typeinfer_expr [] lambda
    pretty_ty ty |> printfn "%s"

test ()   // 'a -> 'a
test ()   // 'b -> 'b
test ()   // 'c -> 'c
```

Note that a fresh type variable is generated each time the test runs. Maybe you need a way to reset the counter between invocations? Or, even better, see if you can get rid of the side-effect in generate_fresh_variable entirely.

Body:
I'm currently building a program to type inference in F# using the following AST:

// errors
//

exception SyntaxError of string * FSharp.Text.Lexing.LexBuffer<char>
exception TypeError of string
exception UnexpectedError of string

let throw_formatted exnf fmt = ksprintf (fun s -> raise (exnf s)) fmt

let unexpected_error fmt = throw_formatted UnexpectedError fmt

// AST type definitions
//

type tyvar = string

type ty =
    | TyName of string //constants
    | TyArrow of ty * ty
    | TyVar of tyvar //'a,'b for example
    | TyTuple of ty list

// pseudo data constructors for literal types
let TyFloat = TyName "float"
let TyInt = TyName "int"
let TyChar = TyName "char"
let TyString = TyName "string"
let TyBool = TyName "bool"
let TyUnit = TyName "unit"

// active pattern for literal types
let private (|TyLit|_|) name = function
    | TyName s when s = name -> Some ()
    | _ -> None

let (|TyFloat|_|) = (|TyLit|_|) "float"
let (|TyInt|_|) = (|TyLit|_|) "int"
let (|TyChar|_|) = (|TyLit|_|) "char"
let (|TyString|_|) = (|TyLit|_|) "string"
let (|TyBool|_|) = (|TyLit|_|) "bool"
let (|TyUnit|_|) = (|TyLit|_|) "unit"

type scheme = Forall of tyvar list * ty

type lit = LInt of int
         | LFloat of float
         | LString of string
         | LChar of char
         | LBool of bool
         | LUnit

type binding = bool * string * ty option * expr    // (is_recursive, id, optional_type_annotation, expression)

and expr =
    | Lit of lit
    | Lambda of string * ty option * expr
    | App of expr * expr
    | Var of string
    | LetIn of binding * expr
    | IfThenElse of expr * expr * expr option
    | Tuple of expr list
    | BinOp of expr * string * expr
    | UnOp of string * expr

let fold_params parms e0 =
 List.foldBack (fun (id, tyo) e -> Lambda (id, tyo, e)) parms e0

let (|Let|_|) = function
    | LetIn ((false, x, tyo, e1), e2) -> Some (x, tyo, e1, e2)
    | _ -> None

let (|LetRec|_|) = function
    | LetIn ((true, x, tyo, e1), e2) -> Some (x, tyo, e1, e2)
    | _ -> None

type 'a env = (string * 'a) list

type value =
    | VLit of lit
    | VTuple of value list
    | Closure of value env * string * expr
    | RecClosure of value env * string * string * expr

type interactive = IExpr of expr | IBinding of binding

// pretty printers
//

// utility function for printing lists by flattening strings with a separator
let rec flatten p sep es =
    match es with
    | [] -> ""
    | [e] -> p e
    | e :: es -> sprintf "%s%s %s" (p e) sep (flatten p sep es)

// print pairs within the given env using p as printer for the elements bound within
let pretty_env p env = sprintf "[%s]" (flatten (fun (x, o) -> sprintf "%s=%s" x (p o)) ";" env)

// print any tuple given a printer p for its elements
let pretty_tupled p l = flatten p ", " l

let rec pretty_ty t =
    match t with
    | TyName s -> s
    | TyArrow (t1, t2) -> sprintf "%s -> %s" (pretty_ty t1) (pretty_ty t2)
    | TyVar n -> sprintf "'%s" n
    | TyTuple ts -> sprintf "(%s)" (pretty_tupled pretty_ty ts)

let pretty_lit lit =
    match lit with
    | LInt n -> sprintf "%d" n
    | LFloat n -> sprintf "%g" n
    | LString s -> sprintf "\"%s\"" s
    | LChar c -> sprintf "%c" c
    | LBool true -> "true"
    | LBool false -> "false"
    | LUnit -> "()"

let rec pretty_expr e =
    match e with
    | Lit lit -> pretty_lit lit

    | Lambda (x, None, e) -> sprintf "fun %s -> %s" x (pretty_expr e)
    | Lambda (x, Some t, e) -> sprintf "fun (%s : %s) -> %s" x (pretty_ty t) (pretty_expr e)

    // TODO pattern-match sub-application cases
    | App (e1, e2) -> sprintf "%s %s" (pretty_expr e1) (pretty_expr e2)

    | Var x -> x

    | Let (x, None, e1, e2) ->
        sprintf "let %s = %s in %s" x (pretty_expr e1) (pretty_expr e2)

    | Let (x, Some t, e1, e2) ->
        sprintf "let %s : %s = %s in %s" x (pretty_ty t) (pretty_expr e1) (pretty_expr e2)

    | LetRec (x, None, e1, e2) ->
        sprintf "let rec %s = %s in %s" x (pretty_expr e1) (pretty_expr e2)

    | LetRec (x, Some tx, e1, e2) ->
        sprintf "let rec %s : %s = %s in %s" x (pretty_ty tx) (pretty_expr e1) (pretty_expr e2)

    | IfThenElse (e1, e2, e3o) ->
        let s = sprintf "if %s then %s" (pretty_expr e1) (pretty_expr e2)
        match e3o with
        | None -> s
        | Some e3 -> sprintf "%s else %s" s (pretty_expr e3)

    | Tuple es ->
        sprintf "(%s)" (pretty_tupled pretty_expr es)

    | BinOp (e1, op, e2) -> sprintf "%s %s %s" (pretty_expr e1) op (pretty_expr e2)

    | UnOp (op, e) -> sprintf "%s %s" op (pretty_expr e)

    | _ -> unexpected_error "pretty_expr: %s" (pretty_expr e)

let rec pretty_value v =
    match v with
    | VLit lit -> pretty_lit lit

    | VTuple vs -> pretty_tupled pretty_value vs

    | Closure (env, x, e) -> sprintf "<|%s;%s;%s|>" (pretty_env pretty_value env) x (pretty_expr e)

    | RecClosure (env, f, x, e) -> sprintf "<|%s;%s;%s;%s|>" (pretty_env pretty_value env) f x (pretty_expr e)

and the type inference algorithm is the following:

let type_error fmt = throw_formatted TypeError fmt

type subst = (tyvar * ty) list

// type inference
//

// starting environment with operation
let gamma0 : scheme env = [
    ("+", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("-", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("*", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("/", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("%", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyInt))))
    ("=", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<=", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    (">", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("=>", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("<>", Forall([],TyArrow (TyInt, TyArrow (TyInt, TyBool))))
    ("and", Forall([],TyArrow (TyBool, TyArrow (TyBool, TyBool))))
    ("or", Forall([],TyArrow (TyBool, TyArrow (TyBool, TyBool))))
    ("not", Forall([],TyArrow (TyBool, TyBool)))
    ("-", Forall([],TyArrow (TyInt, TyInt)))

    ("+.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("-.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("*.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("/.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("%.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyFloat))))
    ("=.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<=.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    (">.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("=>.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("<>.", Forall([],TyArrow (TyFloat, TyArrow (TyFloat, TyBool))))
    ("-.", Forall([],TyArrow (TyFloat, TyFloat)))
]

let mutable counter = -1

let generate_fresh_variable () =
    counter <- counter + 1
    counter + int 'a'
        |> char
        |> string

let rec occurs (tv : tyvar) (t : ty) : bool =
    match t with
    | TyVar t1 -> tv = t1
    | TyArrow (t1,t2) -> occurs tv t1 || occurs tv t2
    | TyName t1 -> false
    | TyTuple tt -> let rec occ_list (tv : tyvar) (t : ty list) : bool =
                        match t with
                        |[] -> false
                        |head::tail -> if occurs tv head
                                       then true
                                       else occ_list tv tail
                    occ_list tv tt

// TODO implement this
let compose_subst (s1 : subst) (s2 : subst) : subst = s1 @ s2

// TODO implement this
let rec unify (t1 : ty) (t2 : ty) : subst =
    match t1, t2 with
    | TyName n1, TyName n2 -> if n1 <> n2
                              then type_error "unify: unification between different variables name can't be execute"
                              else []
    | TyVar tv, _ -> if occurs tv t2
                     then type_error "unify: unification fails"
                     else [(tv , t2)]

    | _ , TyVar tv -> if occurs tv t1
                      then type_error "unify: unification fails"
                      else [(tv , t1)]

    | TyArrow (tl1,tr1), TyArrow (tl2,tr2) ->   let u1 = unify tl1 tl2
                                                let u2 = unify tr1 tr2
                                                compose_subst u1 u2

                                                (*let subs1 = unify tl1 tl2
                                                let te1 = apply_subst tr1 subs1
                                                let te2 = apply_subst tr2 subs1
                                                let subs2 = unify te1 te2
                                                compose_subst subs1 subs2*)
    | _ -> unexpected_error "unify: unsupported operation"

(* substitute term s for all occurrences of var x in term t *)
let rec subst (s : ty) (x : tyvar) (t : ty) : ty =
  match t with
  | TyVar y -> if x = y then s else t
  | TyArrow (u, v) -> TyArrow (subst s x u, subst s x v)
  | TyName n -> t
  | TyTuple ts -> TyTuple(List.map (subst s x) ts)

// TODO implement this
let apply_subst (t : ty) (s : subst) : ty =
  List.foldBack (fun (x, e) -> subst e x) s t

let apply_subst_helper s t = apply_subst t s

// Give all tyvar in a type -> FV
let rec freevars_ty (t : ty) : tyvar Set =
    match t with
    | TyName _ -> Set.empty
    | TyArrow (t1, t2) -> Set.union (freevars_ty t1) (freevars_ty t2)
    | TyVar tv -> Set.singleton tv
    | TyTuple ts -> List.fold (fun set t -> Set.union set (freevars_ty t)) Set.empty ts

let freevars_scheme (Forall (tvs, t)) =
    Set.difference (freevars_ty t) (Set.ofList tvs)

let rec freevars_env (en: scheme env) : tyvar Set =
    match en with
    | [] -> Set.empty
    | e  -> match e with
            |(_,sc)::tail -> Set.union (freevars_env tail) (freevars_scheme sc)

let generalize (env : scheme env) (typ : ty) : scheme =
    let vars = Set.difference (freevars_ty typ) (freevars_env env)
    Forall (Set.toList vars, typ)

let instantiate (Forall (tvs, typ)) : ty =
    let nvars = List.map (fun _ -> TyVar(generate_fresh_variable()) ) tvs
    let s = Map.ofSeq (Seq.zip tvs nvars) |> Map.toList
    apply_subst typ s

let rec tupleMap l: subst =
    match l with
    |[] -> []
    |head::tail ->
                   match head with
                   |(_,su) -> compose_subst su (tupleMap tail)

let rec tupleMap2 l: ty list =
    match l with
    |[] -> []
    |head::tail ->
                   match head with
                   |(typ,_) -> typ::(tupleMap2 tail)
// type inference
//

let rec typeinfer_expr (env : scheme env) (e : expr) : ty * subst =
    match e with
    | Var x ->
        let _, t = List.find (fun (y, _) -> x = y) env
        (instantiate t, [])

    | Lit (LInt _) -> (TyInt, [])
    | Lit (LFloat _) -> (TyFloat, [])
    | Lit (LString _) -> (TyString, [])
    | Lit (LChar _) -> (TyChar, [])
    | Lit (LBool _) -> (TyBool, [])
    | Lit LUnit -> (TyUnit, [])

    | App (e1, e2) ->
        let codTy = TyVar(generate_fresh_variable ())
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr env e2
        let s3 = unify t1 (TyArrow (t2,codTy))
        let s32 = compose_subst s3 s2
        let s321 = compose_subst s32 s1
        (apply_subst codTy s321, s321)

    | Lambda (x, None, e) ->
        let freshVar = TyVar(generate_fresh_variable())
        let sc1 = Forall(list.Empty,freshVar) //46:00 lesson 30 november
        let t,s = typeinfer_expr((x, sc1) :: env) e
        let finalType = apply_subst (TyArrow(freshVar,t)) s
        (finalType,s)

    | Lambda (x, Some typ, e) ->
        let sc1 = Forall(list.Empty,typ)
        let t,s = typeinfer_expr((x, sc1) :: env) e
        let finalType = apply_subst (TyArrow(typ,t)) s
        (finalType,s)

    //monomorphic version
    (*| Let (x, None , e1, e2) ->
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr ((x,t1) :: env) e2
        let s3 = compose_subst s2 s1
        (t2, s3)*)

    //polimorphic version
    | Let (x, None , e1, e2) ->
        let t1, s1 = typeinfer_expr env e1
        //Generalize
        let sc1 = generalize env t1
        let t2, s2 = typeinfer_expr ((x,sc1) :: env) e2
        let s3 = compose_subst s2 s1
        (t2, s3)

    | IfThenElse (e1, e2, e3o) ->
        let t1, s1 = typeinfer_expr env e1
        let t2, s2 = typeinfer_expr env e2
        let s4 = unify t1 TyBool
        match e3o with
        | None -> let s5 = unify t2 TyUnit
                  let tot = compose_subst (compose_subst (compose_subst s5 s4) s2) s1
                  (apply_subst t2 s5, tot)

        | Some ex -> let t3, s3 = typeinfer_expr env ex
                     let s5 = unify t2 t3
                     let tot = compose_subst (compose_subst (compose_subst (compose_subst s5 s4) s3) s2) s1
                     (apply_subst t2 s5, tot)

    | Tuple es ->
        let t = List.map (typeinfer_expr env) es
        let comp = tupleMap t
        let typL =  tupleMap2 t
        let typ = TyTuple(List.map (apply_subst_helper comp) typL)
        (typ,comp)

    | BinOp(e1, op, e2) ->
        typeinfer_expr env (App (App (Var op, e1), e2))

    | BinOp (_, op, _) -> unexpected_error "typecheck_expr: unsupported binary operator (%s)" op

    | UnOp(op, e) ->
        typeinfer_expr env (App (Var op, e))

    | UnOp (op, _) -> unexpected_error "typeinfer_expr: unsupported unary operator (%s)" op

    | _ -> unexpected_error "typeinfer_expr: unsupported expression: %s [AST: %A]" (pretty_expr e) e

I would like to have some explanation on why when I start the program and write inside the shell the following line:

let test = fun x -> x;;

the type returned by the type inference is 'b ->'b and not 'a ->' a.

it's probably because in the process of type inference the function generate_fresh_variable () is called twice for the lamba and for the var, but I would like to understand how I can make it come out as type 'a ->' a?

Obviously I accept suggestions on how to improve the code and how to better implement the algorithm, I apologize for my lack of experience but it is the first time that I look at F # and the type inference.

Body:
My guess is that you inferred the type of another expression before this one, which caused the variable counter to increment. For example, consider the following test code:

let test () =
    let lambda = Lambda ("x", None, Var "x")   // fun x -> x
    let ty, subs = typeinfer_expr [] lambda
    pretty_ty ty |> printfn "%s"

test ()   // 'a -> 'a
test ()   // 'b -> 'b
test ()   // 'c -> 'c

Note that a fresh type variable is generated each time the test runs. Maybe you need a way to reset the counter between invocations? Or, even better, see if you can get rid of the side-effect in generate_fresh_variable entirely.


问:
Is this possible in SQL? Min and Max Dates On a Total. Where it changes in between Dates
I am trying to figure out how to write a query that will give me the correct historical data between dates. But only using sql. I know it is possible coding a loop, but I'm not sure if this is possible in a SQL query. Dates: DD/MM/YYYY

An Example of Data

ID
Points
DATE

1
10
01/01/2018

1
20
02/01/2019

1
25
03/01/2020

1
10
04/01/2021

With a simple query

```<code>SELECT ID, Points, MIN(Date), MAX(Date)
FROM table
GROUP BY ID,POINTS
</code>```

The Min date for 10 points would be 01/01/2018, and the Max Date would be 04/01/2021. Which would be wrong in this instance. As It should be:

ID
Points
Min DATE
Max DATE

1
10
01/01/2018
01/01/2019

1
20
02/01/2019
02/01/2020

1
25
03/01/2020
03/01/2021

1
10
04/01/2021
04/01/2021

I was thinking of using LAG, but need some ideas here. What I haven't told you is there is a record per day. So I would need to group until a change of points. This is to create a view from the data that I already have.

答:
We can do this by creating two tables one with the minimum and one with the maximum date for each grouping and then combining them

```<code>CREATE TABLE dataa(
    id INT,
    points INT,
    ddate DATE);
INSERT INTO dataa values(1 , 10 ,'2018-10-01');
INSERT INTO dataa values(1 , 20 ,'2019-01-02');
INSERT INTO dataa values(1 , 25 ,'2020-01-03');
INSERT INTO dataa values(1 , 10 ,'2021-01-04');
SELECT
    mi.id, mi.points,mi.date minDate, ma.date maxDate
FROM
    (select id, points, min(ddate) date from dataa group by id,points) mi
JOIN
    (select id, points, max(ddate) date from dataa group by id,points) ma
ON
    mi.id = ma.id
AND
    mi.points = ma.points;
DROP TABLE dataa;
</code>```

this gives the following output

```<code>+------+--------+------------+------------+
| id   | points | minDate    | maxDate    |
+------+--------+------------+------------+
|    1 |     10 | 2018-10-01 | 2021-01-04 |
|    1 |     20 | 2019-01-02 | 2019-01-02 |
|    1 |     25 | 2020-01-03 | 2020-01-03 |
+------+--------+------------+------------+
</code>```

I've used the default date formatting. This could be modified if you wish.

Body:
I am trying to figure out how to write a query that will give me the correct historical data between dates. But only using sql. I know it is possible coding a loop, but I'm not sure if this is possible in a SQL query. Dates: DD/MM/YYYY

An Example of Data

ID
Points
DATE

1
10
01/01/2018

1
20
02/01/2019

1
25
03/01/2020

1
10
04/01/2021

With a simple query

SELECT ID, Points, MIN(Date), MAX(Date)
FROM table
GROUP BY ID,POINTS

The Min date for 10 points would be 01/01/2018, and the Max Date would be 04/01/2021. Which would be wrong in this instance. As It should be:

ID
Points
Min DATE
Max DATE

1
10
01/01/2018
01/01/2019

1
20
02/01/2019
02/01/2020

1
25
03/01/2020
03/01/2021

1
10
04/01/2021
04/01/2021

I was thinking of using LAG, but need some ideas here. What I haven't told you is there is a record per day. So I would need to group until a change of points. This is to create a view from the data that I already have.

Body:
We can do this by creating two tables one with the minimum and one with the maximum date for each grouping and then combining them

CREATE TABLE dataa(
    id INT,
    points INT,
    ddate DATE);
INSERT INTO dataa values(1 , 10 ,'2018-10-01');
INSERT INTO dataa values(1 , 20 ,'2019-01-02');
INSERT INTO dataa values(1 , 25 ,'2020-01-03');
INSERT INTO dataa values(1 , 10 ,'2021-01-04');
SELECT
    mi.id, mi.points,mi.date minDate, ma.date maxDate
FROM
    (select id, points, min(ddate) date from dataa group by id,points) mi
JOIN
    (select id, points, max(ddate) date from dataa group by id,points) ma
ON
    mi.id = ma.id
AND
    mi.points = ma.points;
DROP TABLE dataa;

this gives the following output

+------+--------+------------+------------+
| id   | points | minDate    | maxDate    |
+------+--------+------------+------------+
|    1 |     10 | 2018-10-01 | 2021-01-04 |
|    1 |     20 | 2019-01-02 | 2019-01-02 |
|    1 |     25 | 2020-01-03 | 2020-01-03 |
+------+--------+------------+------------+

I've used the default date formatting. This could be modified if you wish.