问:
Submit a Python script to google compute VM instance, run, store the results and stop the instance
I am new to the google cloud. I want to run a Python script on the VM instance (at the end of the Python script, the result will be save as a file). Since the script will run a long time, I want to submit it from my local Linux console with gcloud commands. And after the script finishes running, the VM instance automatically stops to avoid extra cost, and the result file should be stored somewhere so I can get to it later.

I'm not familiar with Bash commands, I assume I can submit a ".sh" file? What should I put in the file and How can I submit the task to VM instance? Thanks a lot!

答:
You can achieve your desired task by taking advantage of Cloud Functions Storage Triggers and the instance.stop method from the Compute Engine API.

The general idea will be to start the instance with the gcloud compute instance start command, then take advantage of the gcloud compute ssh with the --command flag to run your script within the instance. Make the Python script within the instance upload the file to Cloud Storage using the Cloud Storage Client Library for Python and take advantage of the Cloud Functions Storage Object Finalize event to serve as a trigger to call the Cloud Function and stop the instance.

Create a VM and make sure that you have setup a Firewall rule to allow SSH (allow ingress traffic on TCP port 22) and most importantly that it has enough scopes assigned for write (although I'd recommend you to allow read/write operations) to Cloud Storage Buckets. This can be accomplished by making sure that you are using Compute Engine default service account (with at least the Editor and Storage Object Admin roles assigned) for Identity and API access. If you are using the Console simply select Set access for each API and choose Read Write for storage.

Create a bucket making sure you set the Access Control settings to Uniform.

Use the console or the gcloud compute ssh your-instance to ssh into your VM and create your Python script (don't forget to make it executable by running chmod +x your-script.py). For example, the following script will be stored in the default directory and have the following content:

```<code>#!/usr/bin/env python3
import os
from time import sleep
from google.cloud import storage
bucket_name = 'test-bucket-vmss'
destination_blob_name = 'myuploadedfile.txt'
file_name = 'example_upload_file.txt'
#Create a file
f=open(file_name,'w+')
f.write('This is an example file to upload to Google Cloud Storage')
f.close()
#Simulates that the file takes 5 minutes to be created
sleep(300)
#Upload the file to Google Cloud Storage
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename("./"+file_name)
</code>```

Create a Cloud Function by choosing an Object Finalize Storage Trigger (notice that default is HTTP), by making sure you set the timeout to 9 minutes (max allowed for the time being), choose Python 3.7 for runtime and if you leave the App Engine default service account for authentication make sure that it has the compute.instances.stop permission assigned.
a. The main.py part of the Cloud Function should contain:

```<code>from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from time import sleep

credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Project ID for this request.
project = 'you-project-name'  # TODO: Update placeholder value.
# The name of the zone for this request.
zone = 'the-zone-of-the-vm'  # TODO: Update placeholder value.
# Name of the instance resource to stop.
instance = 'the-name-of-the-vm'  # TODO: Update placeholder value.

def hello_gcs(event, context):
    """Triggered by a change to a Cloud Storage bucket.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    file = event
    print(f"The file: {file['name']} was uploaded to the bucket.")
    #Stopping VM after the file is processed
    sleep(5)
    request = service.instances().stop(project=project, zone=zone, instance=instance)
    response = request.execute()
    print("The VM was stopped.")

</code>```

b. The requirements.txt part of the Cloud Function should contain:

```<code>google-api-python-client
oauth2client
</code>```

and deploy the function.

From your local environment where the Google Cloud SDK is installed make a script or simply run:

```<code>### Start the Compute engine instance
gcloud compute instances start the-name-of-the-vm --zone=the-zone-of-the-vm
### Take advantage of the --command flag to run your script within the Compute Engine instance
gcloud compute ssh instance-2 --command="./your-script.py &" --zone=the-zone-of-the-vm
</code>```

Once the file is uploaded to the Cloud Storage bucket the Cloud Function will take care of stopping the instance.

Body:
You can achieve your desired task by taking advantage of Cloud Functions Storage Triggers and the instance.stop method from the Compute Engine API.

The general idea will be to start the instance with the gcloud compute instance start command, then take advantage of the gcloud compute ssh with the --command flag to run your script within the instance. Make the Python script within the instance upload the file to Cloud Storage using the Cloud Storage Client Library for Python and take advantage of the Cloud Functions Storage Object Finalize event to serve as a trigger to call the Cloud Function and stop the instance.

Create a VM and make sure that you have setup a Firewall rule to allow SSH (allow ingress traffic on TCP port 22) and most importantly that it has enough scopes assigned for write (although I'd recommend you to allow read/write operations) to Cloud Storage Buckets. This can be accomplished by making sure that you are using Compute Engine default service account (with at least the Editor and Storage Object Admin roles assigned) for Identity and API access. If you are using the Console simply select Set access for each API and choose Read Write for storage.

Create a bucket making sure you set the Access Control settings to Uniform.

Use the console or the gcloud compute ssh your-instance to ssh into your VM and create your Python script (don't forget to make it executable by running chmod +x your-script.py). For example, the following script will be stored in the default directory and have the following content:

#!/usr/bin/env python3
import os
from time import sleep
from google.cloud import storage
bucket_name = 'test-bucket-vmss'
destination_blob_name = 'myuploadedfile.txt'
file_name = 'example_upload_file.txt'
#Create a file
f=open(file_name,'w+')
f.write('This is an example file to upload to Google Cloud Storage')
f.close()
#Simulates that the file takes 5 minutes to be created
sleep(300)
#Upload the file to Google Cloud Storage
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename("./"+file_name)

Create a Cloud Function by choosing an Object Finalize Storage Trigger (notice that default is HTTP), by making sure you set the timeout to 9 minutes (max allowed for the time being), choose Python 3.7 for runtime and if you leave the App Engine default service account for authentication make sure that it has the compute.instances.stop permission assigned.
a. The main.py part of the Cloud Function should contain:

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from time import sleep

credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Project ID for this request.
project = 'you-project-name'  # TODO: Update placeholder value.
# The name of the zone for this request.
zone = 'the-zone-of-the-vm'  # TODO: Update placeholder value.
# Name of the instance resource to stop.
instance = 'the-name-of-the-vm'  # TODO: Update placeholder value.

def hello_gcs(event, context):
    """Triggered by a change to a Cloud Storage bucket.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    file = event
    print(f"The file: {file['name']} was uploaded to the bucket.")
    #Stopping VM after the file is processed
    sleep(5)
    request = service.instances().stop(project=project, zone=zone, instance=instance)
    response = request.execute()
    print("The VM was stopped.")

b. The requirements.txt part of the Cloud Function should contain:

google-api-python-client
oauth2client

and deploy the function.

From your local environment where the Google Cloud SDK is installed make a script or simply run:

### Start the Compute engine instance
gcloud compute instances start the-name-of-the-vm --zone=the-zone-of-the-vm
### Take advantage of the --command flag to run your script within the Compute Engine instance
gcloud compute ssh instance-2 --command="./your-script.py &" --zone=the-zone-of-the-vm

Once the file is uploaded to the Cloud Storage bucket the Cloud Function will take care of stopping the instance.


来源: stackexchange

问:
python-docx won't install with loads of errors
I'm trying to install python-docx on CentOS 7 - i've installed it fine on the vagrant box running CentOS 7 but on my live cpanel server i'm just getting all the following issues:

```<code>pip install python-docx
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting python-docx
  Using cached python-docx-0.8.10.tar.gz (5.5 MB)
Requirement already satisfied: lxml>=2.3.2 in /usr/lib64/python2.7/site-packages (from python-docx) (3.2.1)
Using legacy setup.py install for python-docx, since package 'wheel' is not installed.
Installing collected packages: python-docx
    Running setup.py install for python-docx ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_hd1wy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/python-docx
         cwd: /tmp/pip-install-vbrTnn/python-docx/
    Complete output (105 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/docx
    copying docx/blkcntnr.py -> build/lib/docx
    copying docx/shared.py -> build/lib/docx
    copying docx/section.py -> build/lib/docx
    copying docx/shape.py -> build/lib/docx
    copying docx/settings.py -> build/lib/docx
    copying docx/document.py -> build/lib/docx
    copying docx/table.py -> build/lib/docx
    copying docx/__init__.py -> build/lib/docx
    copying docx/compat.py -> build/lib/docx
    copying docx/exceptions.py -> build/lib/docx
    copying docx/package.py -> build/lib/docx
    copying docx/api.py -> build/lib/docx
    creating build/lib/docx/styles
    copying docx/styles/styles.py -> build/lib/docx/styles
    copying docx/styles/__init__.py -> build/lib/docx/styles
    copying docx/styles/style.py -> build/lib/docx/styles
    copying docx/styles/latent.py -> build/lib/docx/styles
    creating build/lib/docx/image
    copying docx/image/bmp.py -> build/lib/docx/image
    copying docx/image/constants.py -> build/lib/docx/image
    copying docx/image/jpeg.py -> build/lib/docx/image
    copying docx/image/tiff.py -> build/lib/docx/image
    copying docx/image/image.py -> build/lib/docx/image
    copying docx/image/__init__.py -> build/lib/docx/image
    copying docx/image/exceptions.py -> build/lib/docx/image
    copying docx/image/png.py -> build/lib/docx/image
    copying docx/image/gif.py -> build/lib/docx/image
    copying docx/image/helpers.py -> build/lib/docx/image
    creating build/lib/docx/opc
    copying docx/opc/oxml.py -> build/lib/docx/opc
    copying docx/opc/shared.py -> build/lib/docx/opc
    copying docx/opc/coreprops.py -> build/lib/docx/opc
    copying docx/opc/part.py -> build/lib/docx/opc
    copying docx/opc/constants.py -> build/lib/docx/opc
    copying docx/opc/spec.py -> build/lib/docx/opc
    copying docx/opc/pkgreader.py -> build/lib/docx/opc
    copying docx/opc/packuri.py -> build/lib/docx/opc
    copying docx/opc/__init__.py -> build/lib/docx/opc
    copying docx/opc/compat.py -> build/lib/docx/opc
    copying docx/opc/exceptions.py -> build/lib/docx/opc
    copying docx/opc/rel.py -> build/lib/docx/opc
    copying docx/opc/package.py -> build/lib/docx/opc
    copying docx/opc/phys_pkg.py -> build/lib/docx/opc
    copying docx/opc/pkgwriter.py -> build/lib/docx/opc
    creating build/lib/docx/text
    copying docx/text/parfmt.py -> build/lib/docx/text
    copying docx/text/font.py -> build/lib/docx/text
    copying docx/text/paragraph.py -> build/lib/docx/text
    copying docx/text/__init__.py -> build/lib/docx/text
    copying docx/text/tabstops.py -> build/lib/docx/text
    copying docx/text/run.py -> build/lib/docx/text
    creating build/lib/docx/enum
    copying docx/enum/section.py -> build/lib/docx/enum
    copying docx/enum/text.py -> build/lib/docx/enum
    copying docx/enum/base.py -> build/lib/docx/enum
    copying docx/enum/shape.py -> build/lib/docx/enum
    copying docx/enum/table.py -> build/lib/docx/enum
    copying docx/enum/__init__.py -> build/lib/docx/enum
    copying docx/enum/dml.py -> build/lib/docx/enum
    copying docx/enum/style.py -> build/lib/docx/enum
    creating build/lib/docx/dml
    copying docx/dml/color.py -> build/lib/docx/dml
    copying docx/dml/__init__.py -> build/lib/docx/dml
    creating build/lib/docx/parts
    copying docx/parts/story.py -> build/lib/docx/parts
    copying docx/parts/numbering.py -> build/lib/docx/parts
    copying docx/parts/styles.py -> build/lib/docx/parts
    copying docx/parts/settings.py -> build/lib/docx/parts
    copying docx/parts/document.py -> build/lib/docx/parts
    copying docx/parts/image.py -> build/lib/docx/parts
    copying docx/parts/__init__.py -> build/lib/docx/parts
    copying docx/parts/hdrftr.py -> build/lib/docx/parts
    creating build/lib/docx/oxml
    copying docx/oxml/shared.py -> build/lib/docx/oxml
    copying docx/oxml/numbering.py -> build/lib/docx/oxml
    copying docx/oxml/styles.py -> build/lib/docx/oxml
    copying docx/oxml/coreprops.py -> build/lib/docx/oxml
    copying docx/oxml/section.py -> build/lib/docx/oxml
    copying docx/oxml/shape.py -> build/lib/docx/oxml
    copying docx/oxml/settings.py -> build/lib/docx/oxml
    copying docx/oxml/document.py -> build/lib/docx/oxml
    copying docx/oxml/table.py -> build/lib/docx/oxml
    copying docx/oxml/__init__.py -> build/lib/docx/oxml
    copying docx/oxml/exceptions.py -> build/lib/docx/oxml
    copying docx/oxml/simpletypes.py -> build/lib/docx/oxml
    copying docx/oxml/xmlchemy.py -> build/lib/docx/oxml
    copying docx/oxml/ns.py -> build/lib/docx/oxml
    creating build/lib/docx/opc/parts
    copying docx/opc/parts/coreprops.py -> build/lib/docx/opc/parts
    copying docx/opc/parts/__init__.py -> build/lib/docx/opc/parts
    creating build/lib/docx/oxml/text
    copying docx/oxml/text/parfmt.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/font.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/paragraph.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/__init__.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/run.py -> build/lib/docx/oxml/text
    creating build/lib/docx/templates
    copying docx/templates/default-header.xml -> build/lib/docx/templates
    error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_hd1wy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/python-docx Check the logs for full command output.
</code>```

I'm not used to using python all that much or PIP so i really have no idea what these errors mean, please could someone help out?

答:
There is a known problem with a prior version of setuptools. If you upgrade that this should go away: How to use PIP to install python-docx?

```<code>pip install -U setuptools
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to install python-docx on CentOS 7 - i've installed it fine on the vagrant box running CentOS 7 but on my live cpanel server i'm just getting all the following issues:

pip install python-docx
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting python-docx
  Using cached python-docx-0.8.10.tar.gz (5.5 MB)
Requirement already satisfied: lxml>=2.3.2 in /usr/lib64/python2.7/site-packages (from python-docx) (3.2.1)
Using legacy setup.py install for python-docx, since package 'wheel' is not installed.
Installing collected packages: python-docx
    Running setup.py install for python-docx ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_hd1wy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/python-docx
         cwd: /tmp/pip-install-vbrTnn/python-docx/
    Complete output (105 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/docx
    copying docx/blkcntnr.py -> build/lib/docx
    copying docx/shared.py -> build/lib/docx
    copying docx/section.py -> build/lib/docx
    copying docx/shape.py -> build/lib/docx
    copying docx/settings.py -> build/lib/docx
    copying docx/document.py -> build/lib/docx
    copying docx/table.py -> build/lib/docx
    copying docx/__init__.py -> build/lib/docx
    copying docx/compat.py -> build/lib/docx
    copying docx/exceptions.py -> build/lib/docx
    copying docx/package.py -> build/lib/docx
    copying docx/api.py -> build/lib/docx
    creating build/lib/docx/styles
    copying docx/styles/styles.py -> build/lib/docx/styles
    copying docx/styles/__init__.py -> build/lib/docx/styles
    copying docx/styles/style.py -> build/lib/docx/styles
    copying docx/styles/latent.py -> build/lib/docx/styles
    creating build/lib/docx/image
    copying docx/image/bmp.py -> build/lib/docx/image
    copying docx/image/constants.py -> build/lib/docx/image
    copying docx/image/jpeg.py -> build/lib/docx/image
    copying docx/image/tiff.py -> build/lib/docx/image
    copying docx/image/image.py -> build/lib/docx/image
    copying docx/image/__init__.py -> build/lib/docx/image
    copying docx/image/exceptions.py -> build/lib/docx/image
    copying docx/image/png.py -> build/lib/docx/image
    copying docx/image/gif.py -> build/lib/docx/image
    copying docx/image/helpers.py -> build/lib/docx/image
    creating build/lib/docx/opc
    copying docx/opc/oxml.py -> build/lib/docx/opc
    copying docx/opc/shared.py -> build/lib/docx/opc
    copying docx/opc/coreprops.py -> build/lib/docx/opc
    copying docx/opc/part.py -> build/lib/docx/opc
    copying docx/opc/constants.py -> build/lib/docx/opc
    copying docx/opc/spec.py -> build/lib/docx/opc
    copying docx/opc/pkgreader.py -> build/lib/docx/opc
    copying docx/opc/packuri.py -> build/lib/docx/opc
    copying docx/opc/__init__.py -> build/lib/docx/opc
    copying docx/opc/compat.py -> build/lib/docx/opc
    copying docx/opc/exceptions.py -> build/lib/docx/opc
    copying docx/opc/rel.py -> build/lib/docx/opc
    copying docx/opc/package.py -> build/lib/docx/opc
    copying docx/opc/phys_pkg.py -> build/lib/docx/opc
    copying docx/opc/pkgwriter.py -> build/lib/docx/opc
    creating build/lib/docx/text
    copying docx/text/parfmt.py -> build/lib/docx/text
    copying docx/text/font.py -> build/lib/docx/text
    copying docx/text/paragraph.py -> build/lib/docx/text
    copying docx/text/__init__.py -> build/lib/docx/text
    copying docx/text/tabstops.py -> build/lib/docx/text
    copying docx/text/run.py -> build/lib/docx/text
    creating build/lib/docx/enum
    copying docx/enum/section.py -> build/lib/docx/enum
    copying docx/enum/text.py -> build/lib/docx/enum
    copying docx/enum/base.py -> build/lib/docx/enum
    copying docx/enum/shape.py -> build/lib/docx/enum
    copying docx/enum/table.py -> build/lib/docx/enum
    copying docx/enum/__init__.py -> build/lib/docx/enum
    copying docx/enum/dml.py -> build/lib/docx/enum
    copying docx/enum/style.py -> build/lib/docx/enum
    creating build/lib/docx/dml
    copying docx/dml/color.py -> build/lib/docx/dml
    copying docx/dml/__init__.py -> build/lib/docx/dml
    creating build/lib/docx/parts
    copying docx/parts/story.py -> build/lib/docx/parts
    copying docx/parts/numbering.py -> build/lib/docx/parts
    copying docx/parts/styles.py -> build/lib/docx/parts
    copying docx/parts/settings.py -> build/lib/docx/parts
    copying docx/parts/document.py -> build/lib/docx/parts
    copying docx/parts/image.py -> build/lib/docx/parts
    copying docx/parts/__init__.py -> build/lib/docx/parts
    copying docx/parts/hdrftr.py -> build/lib/docx/parts
    creating build/lib/docx/oxml
    copying docx/oxml/shared.py -> build/lib/docx/oxml
    copying docx/oxml/numbering.py -> build/lib/docx/oxml
    copying docx/oxml/styles.py -> build/lib/docx/oxml
    copying docx/oxml/coreprops.py -> build/lib/docx/oxml
    copying docx/oxml/section.py -> build/lib/docx/oxml
    copying docx/oxml/shape.py -> build/lib/docx/oxml
    copying docx/oxml/settings.py -> build/lib/docx/oxml
    copying docx/oxml/document.py -> build/lib/docx/oxml
    copying docx/oxml/table.py -> build/lib/docx/oxml
    copying docx/oxml/__init__.py -> build/lib/docx/oxml
    copying docx/oxml/exceptions.py -> build/lib/docx/oxml
    copying docx/oxml/simpletypes.py -> build/lib/docx/oxml
    copying docx/oxml/xmlchemy.py -> build/lib/docx/oxml
    copying docx/oxml/ns.py -> build/lib/docx/oxml
    creating build/lib/docx/opc/parts
    copying docx/opc/parts/coreprops.py -> build/lib/docx/opc/parts
    copying docx/opc/parts/__init__.py -> build/lib/docx/opc/parts
    creating build/lib/docx/oxml/text
    copying docx/oxml/text/parfmt.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/font.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/paragraph.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/__init__.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/run.py -> build/lib/docx/oxml/text
    creating build/lib/docx/templates
    copying docx/templates/default-header.xml -> build/lib/docx/templates
    error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vbrTnn/python-docx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_hd1wy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/python-docx Check the logs for full command output.

I'm not used to using python all that much or PIP so i really have no idea what these errors mean, please could someone help out?

Body:
There is a known problem with a prior version of setuptools. If you upgrade that this should go away: How to use PIP to install python-docx?

pip install -U setuptools


问:
How to implement fill attribute in react-native-svg element
I have a simple triangle drawn with paths/lines, exported from AdobeXD as an SVG, then copied & adjusted SVG code into a react-native project with react-native-svg library elements. I'm trying to fill the background of the element, because I dont want it to be transparent. I thought it would be as simple as using web SVG's fill attribute in the G element, but its not working.

Heres the SVG code:

```<code><Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
    <G fill="#fff" transform="translate(0.682 0.632)">
        <Line
            id="Line_37"
            data-name="Line 37"
            x1="21"
            y1="12"
            transform="translate(0 7)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_38"
            data-name="Line 38"
            y2="19"
            transform="translate(21)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_40"
            data-name="Line 40"
            x1="21"
            y2="7"
            stroke="#fff"
            stroke-linecap="round"
            stroke-width="1"
        />
    </G>
</Svg>
</code>```

Looked at react-native-svg's docs and they say "The fill prop refers to the color inside the shape." but like I said, the fill prop does not work in either the <Svg> element nor the <G> element... Any ideas?

答:
Setting the fill prop on G will have an effect on the child elements (the Line elements in your case), not on the group as a whole.

You can draw a white rectangle that covers the whole SVG to accomplish what you want:

```<code><Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
<Rect
    x="0"
    y="0"
    width="100%"
    height="100%"
    fill="white"
/>
<G fill="#fff" transform="translate(0.682 0.632)">
    <Line
        id="Line_37"
        data-name="Line 37"
        x1="21"
        y1="12"
        transform="translate(0 7)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_38"
        data-name="Line 38"
        y2="19"
        transform="translate(21)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_40"
        data-name="Line 40"
        x1="21"
        y2="7"
        stroke="#fff"
        stroke-linecap="round"
        stroke-width="1"
    />
</G>
</code>```

Body:
I have a simple triangle drawn with paths/lines, exported from AdobeXD as an SVG, then copied & adjusted SVG code into a react-native project with react-native-svg library elements. I'm trying to fill the background of the element, because I dont want it to be transparent. I thought it would be as simple as using web SVG's fill attribute in the G element, but its not working.

Heres the SVG code:

<Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
    <G fill="#fff" transform="translate(0.682 0.632)">
        <Line
            id="Line_37"
            data-name="Line 37"
            x1="21"
            y1="12"
            transform="translate(0 7)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_38"
            data-name="Line 38"
            y2="19"
            transform="translate(21)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_40"
            data-name="Line 40"
            x1="21"
            y2="7"
            stroke="#fff"
            stroke-linecap="round"
            stroke-width="1"
        />
    </G>
</Svg>

Looked at react-native-svg's docs and they say "The fill prop refers to the color inside the shape." but like I said, the fill prop does not work in either the <Svg> element nor the <G> element... Any ideas?

Body:
Setting the fill prop on G will have an effect on the child elements (the Line elements in your case), not on the group as a whole.

You can draw a white rectangle that covers the whole SVG to accomplish what you want:

<Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
<Rect
    x="0"
    y="0"
    width="100%"
    height="100%"
    fill="white"
/>
<G fill="#fff" transform="translate(0.682 0.632)">
    <Line
        id="Line_37"
        data-name="Line 37"
        x1="21"
        y1="12"
        transform="translate(0 7)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_38"
        data-name="Line 38"
        y2="19"
        transform="translate(21)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_40"
        data-name="Line 40"
        x1="21"
        y2="7"
        stroke="#fff"
        stroke-linecap="round"
        stroke-width="1"
    />
</G>


问:
Should I use jquery or jquery mobile or iPad web pages?
I am making a web page "app" for the iPad or ios devices.  Should I use jquery mobile or just regular jquery?  After all they're only web pages aren't they?  Is jquery proper no good for me?  Do I need mobile jquery?

Thanks.

答: I would say yes. One of the main selling points of jQuery mobile is it's touch optimized UI, and the iPad would make heavy use of that functionality.

ContentLicense: CC BY-SA 3.0


问:
Add dataset values as numbers correctly
I want to add the data of some data-attributes within a simple formula. But the values don't get interpreted as numbers, but as strings. I do it like that:

```<code> var nutzer = document.getElementById('chosen_meals').getElementsByTagName('p');
 var kalorien = 0;
 for (var i = 0; i < amountOfMeals_low; i++) {
     var kalorien = kalorien + nutzer[i].dataset.kal;
     console.log(kalorien);
 }
</code>```

And the markup is some like that

Foo

Foo

```

And I do get logged
0
0420
0420180

How would I get it to be the result of 600?

答:
try to convert it using Number or parseInt

e.g.
Number(nutzer[i].dataset.kal)

Title: Add dataset values as numbers correctly

Body:
I want to add the data of some data-attributes within a simple formula. But the values don't get interpreted as numbers, but as strings. I do it like that:

 var nutzer = document.getElementById('chosen_meals').getElementsByTagName('p');
 var kalorien = 0;
 for (var i = 0; i < amountOfMeals_low; i++) {
     var kalorien = kalorien + nutzer[i].dataset.kal;
     console.log(kalorien);
 }

And the markup is some like that

Foo

Foo

And I do get logged
0
0420
0420180

How would I get it to be the result of 600?


问:
How to specify "strict" priors for fixed coefficients in rstanarm?
How do I provide a prior distribution for a coefficient with mean in the range 1e-05 and standard deviation (sd) in the range 1e-06?

What are the distributions to choose for such high precision (sd <= 1e-06) parameters in rstanarm?

1) Student t family

2) Hierarchical shrinkage family

3) Laplace family

4) Dirichlet family

5) others

I have tried using prior = normal(location = 1e-05, scale = 1e-06, autoscale = FALSE), but it takes a lot of time for sampling.

答: I think prior = normal(location = 1e-05, scale = 1e-06, autoscale = FALSE) is your best bet. The fact that it takes a lot of time for sampling is not an indication that anything is wrong with the draws it produces. But I would multiply the outcome by 1 million or divide the predictor by 1 million so that prior = normal(location = .1, scale = 1, autoscale = FALSE) is sensible.


问:
BluetoothLeScanner startScan() is not working without log
I had made app which scan beacon device.

And apparently it worked successfully.

I have not modified the code related to this.

But today, I tried scanning today, It didn't work!

It just left log start scanand scan timeout.

here is my code.

ScanViewModel.kt

```<code>class ScanViewModel(application: Application) : AndroidViewModel(application) {

    companion object{
        private const val TAG = "ScanViewModel"
        private const val UUID = "01122334-4556-6778-899a-abbccddeeff0"
        private const val MIN_RSSI = -85
    }

    private var isScanning = false

    private val bluetoothAdapter: BluetoothAdapter? by lazy(LazyThreadSafetyMode.NONE) {
        val bluetoothManager = application.
            getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
        bluetoothManager.adapter
    }

    private val BluetoothAdapter.isDisabled: Boolean
        get() = !isEnabled

    private val handler = Handler()

    private var runnable = Runnable {
        isScanning = false
        bluetoothAdapter!!.bluetoothLeScanner.stopScan(scanCallback)
        Log.d(TAG, "Scan Timeout")
    }

    fun isBluetoothOn(): Boolean {
        return bluetoothAdapter!!.isDisabled
    }

    fun startScan(time: Long) {
        handler.postDelayed(runnable, time)
        isScanning = true
        bluetoothAdapter!!.bluetoothLeScanner.startScan(scanCallback)
        Log.d(TAG, "Scan is started")
    }

    fun stopScan() {
        isScanning = false
        bluetoothAdapter!!.bluetoothLeScanner.stopScan(scanCallback)
        Log.d(TAG, "Scan is terminated")
    }

    private val scanCallback = object : ScanCallback() {
        override fun onScanResult(callbackType: Int, result: ScanResult?) {
            super.onScanResult(callbackType, result)

            result?.let { it ->
                Log.d(TAG, "find : ${result.device}")

                if (it.rssi < MIN_RSSI) {
                    Log.d(TAG, "rssi (${it.rssi}) is too week. return")
                    return
                }

                if (it.scanRecord == null) {
                    Log.d(TAG, "This device does not have scanRecord. return")
                    return
                }

                val bleDevice = BleCreater.create(it.device, it.rssi, it.scanRecord!!.bytes)

                Log.d(TAG, "uuid : ${bleDevice!!.uuid}, major : ${bleDevice.major}, minor : ${bleDevice.minor}, ${bleDevice.rssi}")

                if (bleDevice.uuid == UUID) {
                    Log.d(TAG, "H/W has been found")

                    stopScan()

                    return
                }
            }
        }

        override fun onBatchScanResults(results: MutableList<ScanResult>?) {
            super.onBatchScanResults(results)
        }

        override fun onScanFailed(errorCode: Int) {
            super.onScanFailed(errorCode)
        }
    }
}
</code>```

ScanActivity

```<code>class ScanActivity : BaseActivity<ActivityScanBinding>(R.layout.activity_scan) {
    private lateinit var vm: ScanViewModel
    private lateinit var viewModelFactory: ViewModelProvider.AndroidViewModelFactory

    private companion object {
        const val SCAN_PERIOD = 10000L
        const val REQUEST_ENABLE_BT = 1000
        const val TAG = "ScanActivity"

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModelFactory = ViewModelProvider.AndroidViewModelFactory(application)
        vm = ViewModelProvider(this, viewModelFactory).get(ScanViewModel::class.java)

        if (BluetoothUtil.isBluetoothAvailable(this)) {
            Log.d(TAG, "This device does not support Bluetooth.")
            finish()
        } else {
            Log.d(TAG, "This device supports Bluetooth.")
        }

        setSupportActionBar(binding.toolbarScan)

        supportActionBar?.let {
            it.setDisplayShowTitleEnabled(false)
            it.setDisplayHomeAsUpEnabled(true)
            it.setHomeAsUpIndicator(R.drawable.ic_keyboard_arrow_left_white_32dp)
        }
    }

    override fun onResume() {
        super.onResume()

        if (vm.isBluetoothOn()) {
            val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)

        } else {

            vm.startScan(SCAN_PERIOD)
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            vm.stopScan()
            finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}
</code>```

As you can see, ScanCallback has some log. I've seen it for sure in logcat!!

but now, I can see only this log.

```<code>2020-05-29 00:42:55.895 21880-21880 D/ViewRootImpl@4646843[MainActivity]: ViewPostIme pointer 0
2020-05-29 00:42:56.054 21880-21880 D/ViewRootImpl@4646843[MainActivity]: ViewPostIme pointer 1
2020-05-29 00:42:56.092 21880-21880 W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@ae4800e
2020-05-29 00:42:56.111 21880-21880 I/MultiWindowDecorSupport: updateCaptionType >> DecorView@b569840[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2020-05-29 00:42:56.112 21880-21880 D/MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@b569840[]
2020-05-29 00:42:56.147 21880-21880 D/ScanActivity: This device supports Bluetooth.
2020-05-29 00:42:56.166 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:42:56.166 21880-21880 I/chatty: uid=10908(com.seoultech.livingtogether_android) identical 1 line
2020-05-29 00:42:56.167 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:42:56.168 21880-21880 D/BluetoothAdapter: BLE support array set: 010011
2020-05-29 00:42:56.168 21880-21880 D/BluetoothLeScanner: Start Scan with callback
2020-05-29 00:42:56.170 21880-21900 D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=12 mScannerId=0
2020-05-29 00:42:56.175 21880-21880 D/ScanViewModel: Scan is started
2020-05-29 00:42:56.181 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: setView = com.android.internal.policy.DecorView@b569840 TM=true MM=false
2020-05-29 00:42:56.184 21880-21880 D/ViewRootImpl@4646843[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
2020-05-29 00:42:56.185 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b68fe3a[MainActivity]
2020-05-29 00:42:56.185 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.200 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)0 dur=7 res=0x7 s={true 524632977408} ch=true
2020-05-29 00:42:56.201 21880-21925 D/OpenGLRenderer: createReliableSurface : 0x7a1deda640, 0x7a268ff000
2020-05-29 00:42:56.202 21880-21925 D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-05-29 00:42:56.217 21880-21929 D/FA: Connected to remote service
2020-05-29 00:42:56.234 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-05-29 00:42:56.234 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b569840[ScanActivity]
2020-05-29 00:42:56.234 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b569840[ScanActivity]
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: startInputInner - Id : 0
2020-05-29 00:42:56.236 21880-21880 I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2020-05-29 00:42:56.237 21880-21880 D/InputTransport: Input channel destroyed: 'ClientS', fd=84
2020-05-29 00:42:56.260 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: MSG_RESIZED: frame=(0,0,1080,2220) ci=(0,63,0,126) vi=(0,63,0,126) or=1
2020-05-29 00:42:56.543 21880-21925 W/libEGL: EGLNativeWindowType 0x7a1deda790 disconnect failed
2020-05-29 00:42:56.547 21880-21880 D/ViewRootImpl@4646843[MainActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)8 dur=4 res=0x5 s={false 0} ch=true
2020-05-29 00:42:56.550 21880-21880 D/ViewRootImpl@4646843[MainActivity]: stopped(true) old=false
2020-05-29 00:42:56.562 21880-21880 D/ViewRootImpl@4646843[MainActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)8 dur=4 res=0x5 s={false 0} ch=false
2020-05-29 00:43:02.899 21880-21886 I/ogether_androi: Compiler allocated 4162KB to compile void android.view.ViewRootImpl.performTraversals()
2020-05-29 00:43:06.185 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:43:06.187 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:43:06.187 21880-21880 D/BluetoothLeScanner: Stop Scan with callback
2020-05-29 00:43:06.194 21880-21880 D/ScanViewModel: Scan Timeout
</code>```

No log, No exception. So I can not find out problem.

I re-executed the code I last succeeded with using the git, but the result was the same.

I'm using Android 10 then and now.

Help me.

答:
A few troubleshooting tips:

Do you know that a bluetooth device is advertising? Try an off-the-shelf app like nRf Connect and make sure one is detected.

Is your bluetooth stack in a bad state?  If so, you may not be able to detect anything in step 1.  Turning bluetooth off and on, or rebooting your phone may fix it.

Did you dynamically request and obtain location permission from the user? You cannot detect beacons unless you do so. Read here.

If you check app permissions does it confirm that location permission has been granted to your app? Go to Settings -> Applications -> Your App and check the granted permissions.

Is bluetooth turned on in phone settings?

Is location turn on in phone settings?

Body:
I had made app which scan beacon device.

And apparently it worked successfully.

I have not modified the code related to this.

But today, I tried scanning today, It didn't work!

It just left log start scanand scan timeout.

here is my code.

ScanViewModel.kt

class ScanViewModel(application: Application) : AndroidViewModel(application) {

    companion object{
        private const val TAG = "ScanViewModel"
        private const val UUID = "01122334-4556-6778-899a-abbccddeeff0"
        private const val MIN_RSSI = -85
    }

    private var isScanning = false

    private val bluetoothAdapter: BluetoothAdapter? by lazy(LazyThreadSafetyMode.NONE) {
        val bluetoothManager = application.
            getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
        bluetoothManager.adapter
    }

    private val BluetoothAdapter.isDisabled: Boolean
        get() = !isEnabled

    private val handler = Handler()

    private var runnable = Runnable {
        isScanning = false
        bluetoothAdapter!!.bluetoothLeScanner.stopScan(scanCallback)
        Log.d(TAG, "Scan Timeout")
    }

    fun isBluetoothOn(): Boolean {
        return bluetoothAdapter!!.isDisabled
    }

    fun startScan(time: Long) {
        handler.postDelayed(runnable, time)
        isScanning = true
        bluetoothAdapter!!.bluetoothLeScanner.startScan(scanCallback)
        Log.d(TAG, "Scan is started")
    }

    fun stopScan() {
        isScanning = false
        bluetoothAdapter!!.bluetoothLeScanner.stopScan(scanCallback)
        Log.d(TAG, "Scan is terminated")
    }

    private val scanCallback = object : ScanCallback() {
        override fun onScanResult(callbackType: Int, result: ScanResult?) {
            super.onScanResult(callbackType, result)

            result?.let { it ->
                Log.d(TAG, "find : ${result.device}")

                if (it.rssi < MIN_RSSI) {
                    Log.d(TAG, "rssi (${it.rssi}) is too week. return")
                    return
                }

                if (it.scanRecord == null) {
                    Log.d(TAG, "This device does not have scanRecord. return")
                    return
                }

                val bleDevice = BleCreater.create(it.device, it.rssi, it.scanRecord!!.bytes)

                Log.d(TAG, "uuid : ${bleDevice!!.uuid}, major : ${bleDevice.major}, minor : ${bleDevice.minor}, ${bleDevice.rssi}")

                if (bleDevice.uuid == UUID) {
                    Log.d(TAG, "H/W has been found")

                    stopScan()

                    return
                }
            }
        }

        override fun onBatchScanResults(results: MutableList<ScanResult>?) {
            super.onBatchScanResults(results)
        }

        override fun onScanFailed(errorCode: Int) {
            super.onScanFailed(errorCode)
        }
    }
}

ScanActivity

class ScanActivity : BaseActivity<ActivityScanBinding>(R.layout.activity_scan) {
    private lateinit var vm: ScanViewModel
    private lateinit var viewModelFactory: ViewModelProvider.AndroidViewModelFactory

    private companion object {
        const val SCAN_PERIOD = 10000L
        const val REQUEST_ENABLE_BT = 1000
        const val TAG = "ScanActivity"

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModelFactory = ViewModelProvider.AndroidViewModelFactory(application)
        vm = ViewModelProvider(this, viewModelFactory).get(ScanViewModel::class.java)

        if (BluetoothUtil.isBluetoothAvailable(this)) {
            Log.d(TAG, "This device does not support Bluetooth.")
            finish()
        } else {
            Log.d(TAG, "This device supports Bluetooth.")
        }

        setSupportActionBar(binding.toolbarScan)

        supportActionBar?.let {
            it.setDisplayShowTitleEnabled(false)
            it.setDisplayHomeAsUpEnabled(true)
            it.setHomeAsUpIndicator(R.drawable.ic_keyboard_arrow_left_white_32dp)
        }
    }

    override fun onResume() {
        super.onResume()

        if (vm.isBluetoothOn()) {
            val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)

        } else {

            vm.startScan(SCAN_PERIOD)
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            vm.stopScan()
            finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}

As you can see, ScanCallback has some log. I've seen it for sure in logcat!!

but now, I can see only this log.

2020-05-29 00:42:55.895 21880-21880 D/ViewRootImpl@4646843[MainActivity]: ViewPostIme pointer 0
2020-05-29 00:42:56.054 21880-21880 D/ViewRootImpl@4646843[MainActivity]: ViewPostIme pointer 1
2020-05-29 00:42:56.092 21880-21880 W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@ae4800e
2020-05-29 00:42:56.111 21880-21880 I/MultiWindowDecorSupport: updateCaptionType >> DecorView@b569840[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2020-05-29 00:42:56.112 21880-21880 D/MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@b569840[]
2020-05-29 00:42:56.147 21880-21880 D/ScanActivity: This device supports Bluetooth.
2020-05-29 00:42:56.166 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:42:56.166 21880-21880 I/chatty: uid=10908(com.seoultech.livingtogether_android) identical 1 line
2020-05-29 00:42:56.167 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:42:56.168 21880-21880 D/BluetoothAdapter: BLE support array set: 010011
2020-05-29 00:42:56.168 21880-21880 D/BluetoothLeScanner: Start Scan with callback
2020-05-29 00:42:56.170 21880-21900 D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=12 mScannerId=0
2020-05-29 00:42:56.175 21880-21880 D/ScanViewModel: Scan is started
2020-05-29 00:42:56.181 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: setView = com.android.internal.policy.DecorView@b569840 TM=true MM=false
2020-05-29 00:42:56.184 21880-21880 D/ViewRootImpl@4646843[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
2020-05-29 00:42:56.185 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b68fe3a[MainActivity]
2020-05-29 00:42:56.185 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.200 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)0 dur=7 res=0x7 s={true 524632977408} ch=true
2020-05-29 00:42:56.201 21880-21925 D/OpenGLRenderer: createReliableSurface : 0x7a1deda640, 0x7a268ff000
2020-05-29 00:42:56.202 21880-21925 D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-05-29 00:42:56.217 21880-21929 D/FA: Connected to remote service
2020-05-29 00:42:56.234 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-05-29 00:42:56.234 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b569840[ScanActivity]
2020-05-29 00:42:56.234 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: prepareNavigationBarInfo() DecorView@b569840[ScanActivity]
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: getNavigationBarColor() -855310
2020-05-29 00:42:56.236 21880-21880 D/InputMethodManager: startInputInner - Id : 0
2020-05-29 00:42:56.236 21880-21880 I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2020-05-29 00:42:56.237 21880-21880 D/InputTransport: Input channel destroyed: 'ClientS', fd=84
2020-05-29 00:42:56.260 21880-21880 D/ViewRootImpl@e2f6c46[ScanActivity]: MSG_RESIZED: frame=(0,0,1080,2220) ci=(0,63,0,126) vi=(0,63,0,126) or=1
2020-05-29 00:42:56.543 21880-21925 W/libEGL: EGLNativeWindowType 0x7a1deda790 disconnect failed
2020-05-29 00:42:56.547 21880-21880 D/ViewRootImpl@4646843[MainActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)8 dur=4 res=0x5 s={false 0} ch=true
2020-05-29 00:42:56.550 21880-21880 D/ViewRootImpl@4646843[MainActivity]: stopped(true) old=false
2020-05-29 00:42:56.562 21880-21880 D/ViewRootImpl@4646843[MainActivity]: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)8 dur=4 res=0x5 s={false 0} ch=false
2020-05-29 00:43:02.899 21880-21886 I/ogether_androi: Compiler allocated 4162KB to compile void android.view.ViewRootImpl.performTraversals()
2020-05-29 00:43:06.185 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:43:06.187 21880-21880 D/BluetoothAdapter: STATE_ON
2020-05-29 00:43:06.187 21880-21880 D/BluetoothLeScanner: Stop Scan with callback
2020-05-29 00:43:06.194 21880-21880 D/ScanViewModel: Scan Timeout

No log, No exception. So I can not find out problem.

I re-executed the code I last succeeded with using the git, but the result was the same.

I'm using Android 10 then and now.

Help me.


问:
executing Jmeter on a AIX box
I have developed scripts with Jmeter 5.1.1 in Windows machine. I want to execute those JMeter scripts in AIX box.

Please let me know the process to execute JMeter scripts in AIX box.

Thanks
Raghav

答:
As per Apache JMeter project main page:

The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance.

So given you have Java version 8 or higher installed on your AIX machine - you should be able to download and install JMeter there without any issues and execute the script, you created on your Windows machine normally. Check out Identifying the Java versions and Java installation locations for an AIX system article for more details on how to check existing Java installation and install Java if it is not there.

Also be aware that according to 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article you should always be using the latest version of JMeter (which is JMeter 5.3 as of now) so probably right now it's the best time to perform the upgrade. You can always obtain the latest stable JMeter version from JMeter Downloads page

Title: executing Jmeter on a AIX box


问:
How to import the react-native-osc library in a react-native mobile application?
I am not able to import from react-native-osc library in my react-native project. The import results in an 'undefined' object.

I did install the library with npm:

```<code>$ npm install react-native-osc --save
</code>```

In the App.js script, the object library is imported, anyway when I run the application in an Expo.io environment, the object osc is 'undefiend':

```<code>import osc from 'react-native-osc';
console.log(osc); // it will log 'undefined' on expo.io Android and expo.io web.
</code>```

How to import the OSC functionality in a react-native project?

Thanks.

答: Currently react-native-osc does not work with Expo. You need to eject your project from Expo or create a fresh new one with react-native init.</p>

Body:
I am not able to import from react-native-osc library in my react-native project. The import results in an 'undefined' object.

I did install the library with npm:

$ npm install react-native-osc --save

In the App.js script, the object library is imported, anyway when I run the application in an Expo.io environment, the object osc is 'undefiend':

import osc from 'react-native-osc';
console.log(osc); // it will log 'undefined' on expo.io Android and expo.io web.

How to import the OSC functionality in a react-native project?

Thanks.


问:
maven offers itself postgreSQL driver dependency but then doesn't see it
I tried to connect PostgreSQL connector driver with maven but it doesn't find this dependency

I tried to add driver as .jar file with Project structure and it worked, but I want to add it just like dependency in maven.

答:
Since IntelliJ IDEA 2020.1, it will no longer automatically import updates from your pom.xml when you make changes within the IDE (it will import when - for example - updating from version control). You need to explicitly import changes by clicking the floating refresh button (see top right corner inside your pom.xml view) for the changes to your pom.xml to be processed.

As far as I know, the reason for this change is to prevent multiple time-consuming imports when you are updating your pom files.

As indicated in the comments by CrazyCoder, IntelliJ 2020.1.2 will introduce an option to enable automatic import for any changes again.


问:
Why setter function accepts the same datatype as that of its field in typescript?
I am trying to insert a string value to a private array in a typescript class using a setter function.
In my getter function, intellisense says that the value returned is a type mismatch as mentioned in the code below.

```<code>export class Player{
    constructor(private _skills:string[]){}

    get skills(){
        return this._skills  // Type string not assignable to type string[]
    }

    set skills(newSkill:string){
        this._skills = [...this._skills,newSkill]
    }
}
</code>```

On removing the explicit function parameter type newSkill:string to just newSkill, the above error gets resolved as typescript expects an array of strings to be passed in the setter and not just a string.

We can insert a single string  by enclosing it in an array then merging the passed array with the private array field.

```<code>player.skills = ["single skill"]
</code>```

```<code>export class Player{
    constructor(private _skills:string[]){}

    get skills(){
        return this._skills
    }

    set skills(newSkill){
        this._skills = [...this._skills,...newSkill]
    }
}
</code>```

But why should we pass an array and not just a string to the setter function for situations where we need to insert just one skill value to the skills array at a time and not an array of skills?

Why array of just one string and not just string (as a datatype in the setter function) is the question?

Is it possible to avoid the string array datatype and set it to just a string datatype?

Note:
The requirement is to insert/set one string value at a time and not array of values to the skills array using the set keyword of typescript

答:
It has nothing to do with the field. There's no intrinsic connection between skills and _skills. The requirement is that the return type of the getter must match the type of the parameter of the setter.

You can deal with it by using a union type:

```<code>export class Player {
    constructor(private _skills: string[]) {
    }

    get skills() {
        return this._skills;
    }

    set skills(newSkill: string[] | string) {
        if (typeof newSkill === "string") {
            this._skills.push(newSkill);
        } else {
            this._skills = newSkill.slice(); // Note: Completely replaces the value
        }
    }
}
</code>```

...but you shouldn't, for a couple of reasons:

Every use of the getter has to check whether it got a string or a string array, even though it always returns an array.

Asymmetric APIs have been well proven to be hard to learn and hard to use (think document.cookie, shudder). (The API above is asymmetric in fact even though it isn't in definition, since the getter always returns an array.)

Instead, if you want the skills to be an array, make it an array, and have a method that lets you add a single skill or add an array of skills:

```<code>export class Player {
    constructor(private _skills: string[]) {
    }

    // Gets the array of skills -- you might want to make a
    // defensive copy, or return a frozen version or similar
    get skills() {
        return this._skills;
    }

    // Sets the array of skills, OVERWRITING previous ones
    set skills(newSkills: string[]) {
        this._skills = newSkills.slice();
    }

    // Adds one or more skills, which can be given as individual
    // strings or arrays of strings
    addSkills(...skills: (string|string[])[]) {
        // Add all the skills, which
        this._skills.push(...skills.flat());
    }
}
</code>```

(Note: That uses the new flat method.)

Body:
I am trying to insert a string value to a private array in a typescript class using a setter function.
In my getter function, intellisense says that the value returned is a type mismatch as mentioned in the code below.

export class Player{
    constructor(private _skills:string[]){}

    get skills(){
        return this._skills  // Type string not assignable to type string[]
    }

    set skills(newSkill:string){
        this._skills = [...this._skills,newSkill]
    }
}

On removing the explicit function parameter type newSkill:string to just newSkill, the above error gets resolved as typescript expects an array of strings to be passed in the setter and not just a string.

We can insert a single string  by enclosing it in an array then merging the passed array with the private array field.

player.skills = ["single skill"]

export class Player{
    constructor(private _skills:string[]){}

    get skills(){
        return this._skills
    }

    set skills(newSkill){
        this._skills = [...this._skills,...newSkill]
    }
}

But why should we pass an array and not just a string to the setter function for situations where we need to insert just one skill value to the skills array at a time and not an array of skills?

Why array of just one string and not just string (as a datatype in the setter function) is the question?

Is it possible to avoid the string array datatype and set it to just a string datatype?

Note:
The requirement is to insert/set one string value at a time and not array of values to the skills array using the set keyword of typescript

Body:
It has nothing to do with the field. There's no intrinsic connection between skills and _skills. The requirement is that the return type of the getter must match the type of the parameter of the setter.

You can deal with it by using a union type:

export class Player {
    constructor(private _skills: string[]) {
    }

    get skills() {
        return this._skills;
    }

    set skills(newSkill: string[] | string) {
        if (typeof newSkill === "string") {
            this._skills.push(newSkill);
        } else {
            this._skills = newSkill.slice(); // Note: Completely replaces the value
        }
    }
}

...but you shouldn't, for a couple of reasons:

Every use of the getter has to check whether it got a string or a string array, even though it always returns an array.

Asymmetric APIs have been well proven to be hard to learn and hard to use (think document.cookie, shudder). (The API above is asymmetric in fact even though it isn't in definition, since the getter always returns an array.)

Instead, if you want the skills to be an array, make it an array, and have a method that lets you add a single skill or add an array of skills:

export class Player {
    constructor(private _skills: string[]) {
    }

    // Gets the array of skills -- you might want to make a
    // defensive copy, or return a frozen version or similar
    get skills() {
        return this._skills;
    }

    // Sets the array of skills, OVERWRITING previous ones
    set skills(newSkills: string[]) {
        this._skills = newSkills.slice();
    }

    // Adds one or more skills, which can be given as individual
    // strings or arrays of strings
    addSkills(...skills: (string|string[])[]) {
        // Add all the skills, which
        this._skills.push(...skills.flat());
    }
}

(Note: That uses the new flat method.)


问:
split a string but keep together certain substrings
I want to split a character column in a data frame by certain separating characters (i.e. white spaces, commas and semicolons). However, I want to exclude certain phrases (in my example I want to exclude "my test") from the split.

I managed to get the ordinary string split, but don't know how to exclude certain phrases.

```<code>library(tidyverse)

test <- data.frame(string = c("this is a,test;but I want to exclude my test",
                              "this is another;of my tests",
                              "this is my 3rd test"),
                   stringsAsFactors = FALSE)

test %>%
  mutate(new_string = str_split(test$string, pattern = " |,|;")) %>%
  unnest_wider(new_string)
</code>```

This gives:

```<code># A tibble: 3 x 12
  string                                       ...1  ...2  ...3    ...4  ...5  ...6  ...7  ...8  ...9    ...10 ...11
  <chr>                                        <chr> <chr> <chr>   <chr> <chr> <chr> <chr> <chr> <chr>   <chr> <chr>
1 this is a,test;but I want to exclude my test this  is    a       test  but   I     want  to    exclude my    test
2 this is another;of my tests                  this  is    another of    my    tests NA    NA    NA      NA    NA
3 this is my 3rd test                          this  is    my      3rd   test  NA    NA    NA    NA      NA    NA
</code>```

However, my desired output would be (excluding "my test"):

```<code># A tibble: 3 x 12
  string                                       ...1  ...2  ...3    ...4  ...5      ...6  ...7  ...8  ...9    ...10
  <chr>                                        <chr> <chr> <chr>   <chr> <chr>     <chr> <chr> <chr> <chr>   <chr>
1 this is a,test;but I want to exclude my test this  is    a       test  but       I     want  to    exclude my test
2 this is another;of my tests                  this  is    another of    my tests  NA    NA    NA    NA      NA
3 this is my 3rd test                          this  is    my      3rd   test      NA    NA    NA    NA      NA
</code>```

Any idea? (side question: any idea how I can name the columns in the unnest_wider thing?)

答:
An easy workarround would be to add a _ and remove it later:

```<code>test %>%
  mutate(string = gsub("my test", "my_test", string),
    new_string = str_split(string, pattern = "[ ,;]")) %>%
  unnest_wider(new_string) %>%
  mutate_all(~ gsub("my_test", "my test", .x))
</code>```

In order to give the columns more meaningful names you can use the additional options from pivot_wider.

Body:
I want to split a character column in a data frame by certain separating characters (i.e. white spaces, commas and semicolons). However, I want to exclude certain phrases (in my example I want to exclude "my test") from the split.

I managed to get the ordinary string split, but don't know how to exclude certain phrases.

library(tidyverse)

test <- data.frame(string = c("this is a,test;but I want to exclude my test",
                              "this is another;of my tests",
                              "this is my 3rd test"),
                   stringsAsFactors = FALSE)

test %>%
  mutate(new_string = str_split(test$string, pattern = " |,|;")) %>%
  unnest_wider(new_string)

This gives:

# A tibble: 3 x 12
  string                                       ...1  ...2  ...3    ...4  ...5  ...6  ...7  ...8  ...9    ...10 ...11
  <chr>                                        <chr> <chr> <chr>   <chr> <chr> <chr> <chr> <chr> <chr>   <chr> <chr>
1 this is a,test;but I want to exclude my test this  is    a       test  but   I     want  to    exclude my    test
2 this is another;of my tests                  this  is    another of    my    tests NA    NA    NA      NA    NA
3 this is my 3rd test                          this  is    my      3rd   test  NA    NA    NA    NA      NA    NA

However, my desired output would be (excluding "my test"):

# A tibble: 3 x 12
  string                                       ...1  ...2  ...3    ...4  ...5      ...6  ...7  ...8  ...9    ...10
  <chr>                                        <chr> <chr> <chr>   <chr> <chr>     <chr> <chr> <chr> <chr>   <chr>
1 this is a,test;but I want to exclude my test this  is    a       test  but       I     want  to    exclude my test
2 this is another;of my tests                  this  is    another of    my tests  NA    NA    NA    NA      NA
3 this is my 3rd test                          this  is    my      3rd   test      NA    NA    NA    NA      NA

Any idea? (side question: any idea how I can name the columns in the unnest_wider thing?)

Body:
An easy workarround would be to add a _ and remove it later:

test %>%
  mutate(string = gsub("my test", "my_test", string),
    new_string = str_split(string, pattern = "[ ,;]")) %>%
  unnest_wider(new_string) %>%
  mutate_all(~ gsub("my_test", "my test", .x))

In order to give the columns more meaningful names you can use the additional options from pivot_wider.


答:
jQuery mobile helps you out by adding events like swipe and touch hold etc. So if you want the touch capabilities to be integrated into your web page, mobile makes it easier. Caution though, I think it is still beta.

EvoD

Title: Should I use jquery or jquery mobile or iPad web pages?

Body:
I am making a web page "app" for the iPad or ios devices.  Should I use jquery mobile or just regular jquery?  After all they're only web pages aren't they?  Is jquery proper no good for me?  Do I need mobile jquery?

Thanks.


问:
env: node: No such file or directory
env: node: No such file or directory

I checked if my directory for node wasn't wrong and it's fine.

I tried these following answers already:
1. https://github.com/nodejs/node-v0.x-archive/issues/3911
2. https://github.com/creationix/nvm/issues/1702
3. browserify error /usr/bin/env: node: No such file or directory

```<code>USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
acpica                   fantom                   lego                     qmmp
bat                      fn                       libdca                   rubberband
bazel                    fselect                  libpqxx                  ruby-build
cake                     fstar                    nativefier               saxon
calabash                 groovysdk                openimageio              shellcheck
cdrdao                   h2o                      pegtl                    sqlmap
cmake                    hadoop                   percona-server           teleport
conan                    heroku                   phpunit                  urh
convox                   jenkins-job-builder      pike
etcd                     jetty                    ponyc
exomizer                 jetty-runner             pygobject3

Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
  rm '/usr/local/include/node/android-ifaddrs.h'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ brew link --overwrite --dry-run node
Would remove:
/usr/local/include/node/android-ifaddrs.h
/usr/local/include/node/common.gypi
/usr/local/include/node/config.gypi
/usr/local/include/node/libplatform/libplatform-export.h
/usr/local/include/node/libplatform/libplatform.h
/usr/local/include/node/libplatform/v8-tracing.h
/usr/local/include/node/node.h
/usr/local/include/node/node_api.h
/usr/local/include/node/node_api_types.h
/usr/local/include/node/node_buffer.h
/usr/local/include/node/node_object_wrap.h
/usr/local/include/node/node_version.h
/usr/local/include/node/openssl/aes.h
/usr/local/include/node/openssl/asn1.h
/usr/local/include/node/openssl/asn1_mac.h
/usr/local/include/node/openssl/asn1t.h
/usr/local/include/node/openssl/bio.h
/usr/local/include/node/openssl/blowfish.h
/usr/local/include/node/openssl/bn.h
/usr/local/include/node/openssl/buffer.h
/usr/local/include/node/openssl/camellia.h
/usr/local/include/node/openssl/cast.h
/usr/local/include/node/openssl/cmac.h
/usr/local/include/node/openssl/cms.h
/usr/local/include/node/openssl/comp.h
/usr/local/include/node/openssl/conf.h
/usr/local/include/node/openssl/conf_api.h
/usr/local/include/node/openssl/crypto.h
/usr/local/include/node/openssl/des.h
/usr/local/include/node/openssl/dh.h
/usr/local/include/node/openssl/dsa.h
/usr/local/include/node/openssl/dtls1.h
/usr/local/include/node/openssl/e_os2.h
/usr/local/include/node/openssl/ebcdic.h
/usr/local/include/node/openssl/ec.h
/usr/local/include/node/openssl/ecdh.h
/usr/local/include/node/openssl/ecdsa.h
/usr/local/include/node/openssl/engine.h
/usr/local/include/node/openssl/err.h
/usr/local/include/node/openssl/evp.h
/usr/local/include/node/openssl/hmac.h
/usr/local/include/node/openssl/idea.h
/usr/local/include/node/openssl/lhash.h
/usr/local/include/node/openssl/md4.h
/usr/local/include/node/openssl/md5.h
/usr/local/include/node/openssl/mdc2.h
/usr/local/include/node/openssl/modes.h
/usr/local/include/node/openssl/obj_mac.h
/usr/local/include/node/openssl/objects.h
/usr/local/include/node/openssl/ocsp.h
/usr/local/include/node/openssl/opensslconf.h
/usr/local/include/node/openssl/opensslv.h
/usr/local/include/node/openssl/ossl_typ.h
/usr/local/include/node/openssl/pem.h
/usr/local/include/node/openssl/pem2.h
/usr/local/include/node/openssl/pkcs12.h
/usr/local/include/node/openssl/pkcs7.h
/usr/local/include/node/openssl/rand.h
/usr/local/include/node/openssl/rc2.h
/usr/local/include/node/openssl/rc4.h
/usr/local/include/node/openssl/ripemd.h
/usr/local/include/node/openssl/rsa.h
/usr/local/include/node/openssl/safestack.h
/usr/local/include/node/openssl/seed.h
/usr/local/include/node/openssl/sha.h
/usr/local/include/node/openssl/srp.h
/usr/local/include/node/openssl/srtp.h
/usr/local/include/node/openssl/ssl.h
/usr/local/include/node/openssl/ssl2.h
/usr/local/include/node/openssl/ssl3.h
/usr/local/include/node/openssl/stack.h
/usr/local/include/node/openssl/symhacks.h
/usr/local/include/node/openssl/tls1.h
/usr/local/include/node/openssl/ts.h
/usr/local/include/node/openssl/txt_db.h
/usr/local/include/node/openssl/ui.h
/usr/local/include/node/openssl/whrlpool.h
/usr/local/include/node/openssl/x509.h
/usr/local/include/node/openssl/x509_vfy.h
/usr/local/include/node/openssl/x509v3.h
/usr/local/include/node/pthread-barrier.h
/usr/local/include/node/stdint-msvc2008.h
/usr/local/include/node/tree.h
/usr/local/include/node/uv-aix.h
/usr/local/include/node/uv-bsd.h
/usr/local/include/node/uv-darwin.h
/usr/local/include/node/uv-errno.h
/usr/local/include/node/uv-linux.h
/usr/local/include/node/uv-os390.h
/usr/local/include/node/uv-posix.h
/usr/local/include/node/uv-sunos.h
/usr/local/include/node/uv-threadpool.h
/usr/local/include/node/uv-unix.h
/usr/local/include/node/uv-version.h
/usr/local/include/node/uv-win.h
/usr/local/include/node/uv.h
/usr/local/include/node/v8-inspector-protocol.h
/usr/local/include/node/v8-inspector.h
/usr/local/include/node/v8-platform.h
/usr/local/include/node/v8-profiler.h
/usr/local/include/node/v8-testing.h
/usr/local/include/node/v8-util.h
/usr/local/include/node/v8-value-serializer-version.h
/usr/local/include/node/v8-version-string.h
/usr/local/include/node/v8-version.h
/usr/local/include/node/v8.h
/usr/local/include/node/v8config.h
/usr/local/include/node/zconf.h
/usr/local/include/node/zlib.h
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
/usr/local/share/doc/node/lldbinit
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
  rm '/usr/local/include/node/android-ifaddrs.h'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ run node
bash: run: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --force
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --rf
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install -rf node
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ node install yarn
bash: node: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm install yarn
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install yarn -g
Warning: yarn 1.7.0 is already installed and up-to-date
To reinstall 1.7.0, run `brew reinstall yarn`
USER-no-MacBook-Pro-2:nomadcoin user$ brew reinstall yarn
==> Reinstalling yarn
==> Downloading https://yarnpkg.com/downloads/1.7.0/yarn-v1.7.0.tar.gz
Already downloaded: /Users/user/Library/Caches/Homebrew/yarn-1.7.0.tar.gz
  /usr/local/Cellar/yarn/1.7.0: 14 files, 4.2MB, built in 1 second
USER-no-MacBook-Pro-2:nomadcoin user$ yarn install
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/bin/nodejs /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ sudo ln -s /usr/bin/nodejs /usr/bin/node
Password:
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo apt-get install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo brew install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm debug
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm debug
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ sudo chown -R $USER /usr/local
chown: /usr/local: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ npm --version
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm --version
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ nvm install
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/local/Cellar/node /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$
</code>```

答:
Perform the below steps:

which node

sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node

Title: env: node: No such file or directory

Body:
env: node: No such file or directory

I checked if my directory for node wasn't wrong and it's fine.

I tried these following answers already:
1. https://github.com/nodejs/node-v0.x-archive/issues/3911
2. https://github.com/creationix/nvm/issues/1702
3. browserify error /usr/bin/env: node: No such file or directory

USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
acpica                   fantom                   lego                     qmmp
bat                      fn                       libdca                   rubberband
bazel                    fselect                  libpqxx                  ruby-build
cake                     fstar                    nativefier               saxon
calabash                 groovysdk                openimageio              shellcheck
cdrdao                   h2o                      pegtl                    sqlmap
cmake                    hadoop                   percona-server           teleport
conan                    heroku                   phpunit                  urh
convox                   jenkins-job-builder      pike
etcd                     jetty                    ponyc
exomizer                 jetty-runner             pygobject3

Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
  rm '/usr/local/include/node/android-ifaddrs.h'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ brew link --overwrite --dry-run node
Would remove:
/usr/local/include/node/android-ifaddrs.h
/usr/local/include/node/common.gypi
/usr/local/include/node/config.gypi
/usr/local/include/node/libplatform/libplatform-export.h
/usr/local/include/node/libplatform/libplatform.h
/usr/local/include/node/libplatform/v8-tracing.h
/usr/local/include/node/node.h
/usr/local/include/node/node_api.h
/usr/local/include/node/node_api_types.h
/usr/local/include/node/node_buffer.h
/usr/local/include/node/node_object_wrap.h
/usr/local/include/node/node_version.h
/usr/local/include/node/openssl/aes.h
/usr/local/include/node/openssl/asn1.h
/usr/local/include/node/openssl/asn1_mac.h
/usr/local/include/node/openssl/asn1t.h
/usr/local/include/node/openssl/bio.h
/usr/local/include/node/openssl/blowfish.h
/usr/local/include/node/openssl/bn.h
/usr/local/include/node/openssl/buffer.h
/usr/local/include/node/openssl/camellia.h
/usr/local/include/node/openssl/cast.h
/usr/local/include/node/openssl/cmac.h
/usr/local/include/node/openssl/cms.h
/usr/local/include/node/openssl/comp.h
/usr/local/include/node/openssl/conf.h
/usr/local/include/node/openssl/conf_api.h
/usr/local/include/node/openssl/crypto.h
/usr/local/include/node/openssl/des.h
/usr/local/include/node/openssl/dh.h
/usr/local/include/node/openssl/dsa.h
/usr/local/include/node/openssl/dtls1.h
/usr/local/include/node/openssl/e_os2.h
/usr/local/include/node/openssl/ebcdic.h
/usr/local/include/node/openssl/ec.h
/usr/local/include/node/openssl/ecdh.h
/usr/local/include/node/openssl/ecdsa.h
/usr/local/include/node/openssl/engine.h
/usr/local/include/node/openssl/err.h
/usr/local/include/node/openssl/evp.h
/usr/local/include/node/openssl/hmac.h
/usr/local/include/node/openssl/idea.h
/usr/local/include/node/openssl/lhash.h
/usr/local/include/node/openssl/md4.h
/usr/local/include/node/openssl/md5.h
/usr/local/include/node/openssl/mdc2.h
/usr/local/include/node/openssl/modes.h
/usr/local/include/node/openssl/obj_mac.h
/usr/local/include/node/openssl/objects.h
/usr/local/include/node/openssl/ocsp.h
/usr/local/include/node/openssl/opensslconf.h
/usr/local/include/node/openssl/opensslv.h
/usr/local/include/node/openssl/ossl_typ.h
/usr/local/include/node/openssl/pem.h
/usr/local/include/node/openssl/pem2.h
/usr/local/include/node/openssl/pkcs12.h
/usr/local/include/node/openssl/pkcs7.h
/usr/local/include/node/openssl/rand.h
/usr/local/include/node/openssl/rc2.h
/usr/local/include/node/openssl/rc4.h
/usr/local/include/node/openssl/ripemd.h
/usr/local/include/node/openssl/rsa.h
/usr/local/include/node/openssl/safestack.h
/usr/local/include/node/openssl/seed.h
/usr/local/include/node/openssl/sha.h
/usr/local/include/node/openssl/srp.h
/usr/local/include/node/openssl/srtp.h
/usr/local/include/node/openssl/ssl.h
/usr/local/include/node/openssl/ssl2.h
/usr/local/include/node/openssl/ssl3.h
/usr/local/include/node/openssl/stack.h
/usr/local/include/node/openssl/symhacks.h
/usr/local/include/node/openssl/tls1.h
/usr/local/include/node/openssl/ts.h
/usr/local/include/node/openssl/txt_db.h
/usr/local/include/node/openssl/ui.h
/usr/local/include/node/openssl/whrlpool.h
/usr/local/include/node/openssl/x509.h
/usr/local/include/node/openssl/x509_vfy.h
/usr/local/include/node/openssl/x509v3.h
/usr/local/include/node/pthread-barrier.h
/usr/local/include/node/stdint-msvc2008.h
/usr/local/include/node/tree.h
/usr/local/include/node/uv-aix.h
/usr/local/include/node/uv-bsd.h
/usr/local/include/node/uv-darwin.h
/usr/local/include/node/uv-errno.h
/usr/local/include/node/uv-linux.h
/usr/local/include/node/uv-os390.h
/usr/local/include/node/uv-posix.h
/usr/local/include/node/uv-sunos.h
/usr/local/include/node/uv-threadpool.h
/usr/local/include/node/uv-unix.h
/usr/local/include/node/uv-version.h
/usr/local/include/node/uv-win.h
/usr/local/include/node/uv.h
/usr/local/include/node/v8-inspector-protocol.h
/usr/local/include/node/v8-inspector.h
/usr/local/include/node/v8-platform.h
/usr/local/include/node/v8-profiler.h
/usr/local/include/node/v8-testing.h
/usr/local/include/node/v8-util.h
/usr/local/include/node/v8-value-serializer-version.h
/usr/local/include/node/v8-version-string.h
/usr/local/include/node/v8-version.h
/usr/local/include/node/v8.h
/usr/local/include/node/v8config.h
/usr/local/include/node/zconf.h
/usr/local/include/node/zlib.h
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
/usr/local/share/doc/node/lldbinit
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
  rm '/usr/local/include/node/android-ifaddrs.h'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ run node
bash: run: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --force
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --rf
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install -rf node
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ node install yarn
bash: node: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm install yarn
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install yarn -g
Warning: yarn 1.7.0 is already installed and up-to-date
To reinstall 1.7.0, run `brew reinstall yarn`
USER-no-MacBook-Pro-2:nomadcoin user$ brew reinstall yarn
==> Reinstalling yarn
==> Downloading https://yarnpkg.com/downloads/1.7.0/yarn-v1.7.0.tar.gz
Already downloaded: /Users/user/Library/Caches/Homebrew/yarn-1.7.0.tar.gz
  /usr/local/Cellar/yarn/1.7.0: 14 files, 4.2MB, built in 1 second
USER-no-MacBook-Pro-2:nomadcoin user$ yarn install
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/bin/nodejs /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ sudo ln -s /usr/bin/nodejs /usr/bin/node
Password:
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo apt-get install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo brew install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm debug
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm debug
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ sudo chown -R $USER /usr/local
chown: /usr/local: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ npm --version
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm --version
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ nvm install
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/local/Cellar/node /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$


问:
Rails order by foreign key (including nil)
I'm trying to sort column Foo that has one Bar. Currently, I'm using a join so that in the foos#index action is ordered by bars.name*:

```<code>@foos = Foo.joins(:bar).order("bars.name")
</code>```

The problem is, not all foos have a bar, and it seems as though this join ignores any Foo with no Bar. I don't want these records ignored. Is there a way to do this?

*For the record, I'm using will_paginate, so the index action actually includes:

```<code>@foos = Foo.joins(:bar).paginate :page => params[:page], :order => "bars.name"
</code>```

答:
You need to use SQL LEFT JOIN in your joins statement. This will fetch all Foos (with Foos that have Bars)

To use 'Rails way' you can wrap it into the scope:

```<code>scope :some_scope_name, joins("LEFT JOIN bars ON foos.id = bars.foo_id")
</code>```

Body:
I'm trying to sort column Foo that has one Bar. Currently, I'm using a join so that in the foos#index action is ordered by bars.name*:

@foos = Foo.joins(:bar).order("bars.name")

The problem is, not all foos have a bar, and it seems as though this join ignores any Foo with no Bar. I don't want these records ignored. Is there a way to do this?

*For the record, I'm using will_paginate, so the index action actually includes:

@foos = Foo.joins(:bar).paginate :page => params[:page], :order => "bars.name"

Body:
You need to use SQL LEFT JOIN in your joins statement. This will fetch all Foos (with Foos that have Bars)

To use 'Rails way' you can wrap it into the scope:

scope :some_scope_name, joins("LEFT JOIN bars ON foos.id = bars.foo_id")


问:
How to force update CoreData Codefiles (Property Extension) in Swift 5?
i am a bit confused with CoreData. In my xcdatamodeld I am able to create new properties and change some things about them, like whether they are optional or not.

For example, I created a property for my entity and called it descrip, the type is a String and I checked the Optional Field.

At some other point I try to create a new Object of this Entity and safe it to CoreData:

let newEntity = Entity(context: context)
newEntity.name = name
newEntity.descrip = descrip // descrip is an optional String
newEntity.filename = filename
```

<p>I get the following error message: <code>Value of optional type 'String?' must be unwrapped to a value of type 'String'</code></p>

<blockquote>
  <p>Then, I tried to create the NSManagedObjectSubclasses for my Entity. <strong>I discovered, that while all properties have been added and the type of all is set correctly, the ? indicating the Optionality of the property was messed up completely.</strong></p>
</blockquote>

<pre class="lang-swift prettyprint-override"><code>import Foundation
import CoreData

extension Entity {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Entity> {
        return NSFetchRequest<Entity>(entityName: "Entity")
    }

    @NSManaged public var name: String? // Should not be optional and was set so in xcdatamodeld
    @NSManaged public var descrip: String // Should be optional and set to optional in xcdatamodeld
    @NSManaged public var filename: String
}
</code>```

Is there any way to force update this code file? Or how can I use optional strings to fill out my new Entity's optional values?

答:
The error in that assignment is not a Core Data problem, it's pure Swift. You've declared descrip as String, yet you are trying to assign a String? value. That's not legal in Swift-- you must unwrap an optional before assigning it to a non-optional. It would be the same if you weren't using Core Data. For example this would produce the same error:

```<code>let foo: String? = "hello"
let bar: String = foo
</code>```

The differences between the data model and the generated code happen because Swift optionals and Core Data optionals are completely different things. Core Data only cares if something is optional when you save changes. Swift cares about whether something is optional all the time. It's different because Core Data was around for a long time before Swift existed, so it doesn't always match up with what Swift expects.

Body:
i am a bit confused with CoreData. In my xcdatamodeld I am able to create new properties and change some things about them, like whether they are optional or not.

For example, I created a property for my entity and called it descrip, the type is a String and I checked the Optional Field.

At some other point I try to create a new Object of this Entity and safe it to CoreData:

let newEntity = Entity(context: context)
newEntity.name = name
newEntity.descrip = descrip // descrip is an optional String
newEntity.filename = filename

I get the following error message: Value of optional type 'String?' must be unwrapped to a value of type 'String'

Then, I tried to create the NSManagedObjectSubclasses for my Entity. I discovered, that while all properties have been added and the type of all is set correctly, the ? indicating the Optionality of the property was messed up completely.

import Foundation
import CoreData

extension Entity {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Entity> {
        return NSFetchRequest<Entity>(entityName: "Entity")
    }

    @NSManaged public var name: String? // Should not be optional and was set so in xcdatamodeld
    @NSManaged public var descrip: String // Should be optional and set to optional in xcdatamodeld
    @NSManaged public var filename: String
}

Is there any way to force update this code file? Or how can I use optional strings to fill out my new Entity's optional values?

Body:
The error in that assignment is not a Core Data problem, it's pure Swift. You've declared descrip as String, yet you are trying to assign a String? value. That's not legal in Swift-- you must unwrap an optional before assigning it to a non-optional. It would be the same if you weren't using Core Data. For example this would produce the same error:

let foo: String? = "hello"
let bar: String = foo

The differences between the data model and the generated code happen because Swift optionals and Core Data optionals are completely different things. Core Data only cares if something is optional when you save changes. Swift cares about whether something is optional all the time. It's different because Core Data was around for a long time before Swift existed, so it doesn't always match up with what Swift expects.


问:
Count number of identical values between two vectors
```<code>a<-c(19,24,34,47,47,47)
b<-c(3,14,24,25,47,47)
</code>```

I want to know how many values in a match those in b, however i'm running into issues - when there are duplicate numbers present in both vectors. My desired answer for the above example would be 3 - because 24,47,47 - are shared between the two vectors.

If I use intersect:

```<code>intersect(a,b)

[1] 24 47
</code>```

The 2nd matching 47 is ignored.

If I use %in%:

```<code>length(which(a %in% b))
[1] 4
</code>```

The extra 47 in a is also counted.

I realise that I can do:

```<code>length(which(b %in% a))
[1] 3
</code>```

However, I may also have cases where there is an extra matching value in b instead of a and so %in% is also not useful. For example:

```<code>a<-c(19,24,34,7,47,47)
b<-c(3,14,24,47,47,47)
length(which(b %in% a))
[1] 4 (I want the answer to still be 3)
</code>```

So, without rearranging which vector comes first in the %in% function, for each test - I cannot figure out how to do this. Can somebody show me how?

答:
How about:

```<code>sum(pmin(
  table(a[a %in% intersect(a, b)]),
  table(b[b %in% intersect(a, b)])
))
</code>```

We make table()s of the chunks of a, b that are common to both, then we take the smallest numbers from those tables and add them up.

Body:
a<-c(19,24,34,47,47,47)
b<-c(3,14,24,25,47,47)

I want to know how many values in a match those in b, however i'm running into issues - when there are duplicate numbers present in both vectors. My desired answer for the above example would be 3 - because 24,47,47 - are shared between the two vectors.

If I use intersect:

intersect(a,b)

[1] 24 47

The 2nd matching 47 is ignored.

If I use %in%:

length(which(a %in% b))
[1] 4

The extra 47 in a is also counted.

I realise that I can do:

length(which(b %in% a))
[1] 3

However, I may also have cases where there is an extra matching value in b instead of a and so %in% is also not useful. For example:

a<-c(19,24,34,7,47,47)
b<-c(3,14,24,47,47,47)
length(which(b %in% a))
[1] 4 (I want the answer to still be 3)

So, without rearranging which vector comes first in the %in% function, for each test - I cannot figure out how to do this. Can somebody show me how?

Body:
How about:

sum(pmin(
  table(a[a %in% intersect(a, b)]),
  table(b[b %in% intersect(a, b)])
))

We make table()s of the chunks of a, b that are common to both, then we take the smallest numbers from those tables and add them up.