问:
how to convert from fopen to open when trying to open a .data file?
```<code>FILE *inFile = fopen("dataFlow.dat", "r"); // read only
FILE *outFile = fopen("report.dat", "w"); // write only
</code>```

答:
If your files have binary contents, you should open them in binary mode by appending b to the mode string.

For better portability and to take advantage of buffering, using standard streams is recommended over system call such as open, which are tricky to use reliably.

```<code>FILE *inFile = fopen("dataFlow.dat", "rb"); // read only
FILE *outFile = fopen("report.dat", "wb"); // write only
</code>```

For low level system programming on POSIX systems, you can use the open() system call.

Here is a small example that just attempts to copy 1KB from one file to the other:

```<code>#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    unsigned char buf[1024];
    int status = 0;

    int inFile = open("dataFlow.dat", O_RDONLY);
    if (inFile < 0) {
        perror("dataFlow.dat");
        return 1;
    }

    int outFile = open("report.dat", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if (outFile < 0) {
        perror("report.dat");
        close(inFile);
        return 1;
    }

    // this loop is equivalent to nread = fread(buffer, 1, sizeof buffer, inFile);
    int nread = 0;
    while (nread < (int)sizeof(buffer)) {
        ssize_t nr = read(inFile, buffer + nread, sizeof buffer - nread);
        if (nr < 0) {
            if (errno == EINTR)
                continue;
            perror("reading dataFlow");
            status = 1;
            break;
        }
        if (nr == 0)
            break;
        nread += nr;
    }

    // this loop is equivalent to nwritten = fwrite(buffer, 1, nread, outFile);
    int nwritten = 0;
    while (nwritten < nread) {
        ssize_t nw = write(outFile, buffer + nwritten, nread - nwritten);
        if (nw < 0) {
            if (errno == EINTR)
                continue;
            perror("writing report");
            status = 1;
            break;
        }
        if (nw == 0) {
            fprintf(stderr, "cannot write data\n");
            status = 1;
            break;
        }
        nwritten += nw;
    }
    close(inFile);
    close(outFile);

    printf("%d bytes read, %d bytes written\n", nread, nwritten);
    return status;
}
</code>```

Body:
If your files have binary contents, you should open them in binary mode by appending b to the mode string.

For better portability and to take advantage of buffering, using standard streams is recommended over system call such as open, which are tricky to use reliably.

FILE *inFile = fopen("dataFlow.dat", "rb"); // read only
FILE *outFile = fopen("report.dat", "wb"); // write only

For low level system programming on POSIX systems, you can use the open() system call.

Here is a small example that just attempts to copy 1KB from one file to the other:

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    unsigned char buf[1024];
    int status = 0;

    int inFile = open("dataFlow.dat", O_RDONLY);
    if (inFile < 0) {
        perror("dataFlow.dat");
        return 1;
    }

    int outFile = open("report.dat", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if (outFile < 0) {
        perror("report.dat");
        close(inFile);
        return 1;
    }

    // this loop is equivalent to nread = fread(buffer, 1, sizeof buffer, inFile);
    int nread = 0;
    while (nread < (int)sizeof(buffer)) {
        ssize_t nr = read(inFile, buffer + nread, sizeof buffer - nread);
        if (nr < 0) {
            if (errno == EINTR)
                continue;
            perror("reading dataFlow");
            status = 1;
            break;
        }
        if (nr == 0)
            break;
        nread += nr;
    }

    // this loop is equivalent to nwritten = fwrite(buffer, 1, nread, outFile);
    int nwritten = 0;
    while (nwritten < nread) {
        ssize_t nw = write(outFile, buffer + nwritten, nread - nwritten);
        if (nw < 0) {
            if (errno == EINTR)
                continue;
            perror("writing report");
            status = 1;
            break;
        }
        if (nw == 0) {
            fprintf(stderr, "cannot write data\n");
            status = 1;
            break;
        }
        nwritten += nw;
    }
    close(inFile);
    close(outFile);

    printf("%d bytes read, %d bytes written\n", nread, nwritten);
    return status;
}


来源: stackexchange

问:
HPjmeter-like graphical tool to view -agentlib:hprof profiling output
What tools are available to view the output of the built-in JVM profiler? For example, I'm starting my JVM with:

```<code>-agentlib:hprof=cpu=times,thread=y,cutoff=0,format=a,file=someFile.hprof.txt
</code>```

This generates output in the hprof ("JAVA PROFILE 1.0.1") format.

I have had success in the past using HPjmeter to view these output files in a reasonable way. However, for whatever reason the files that are generated using the current version of the Sun JVM fail to load in the current version of HPjmeter:

```<code>java.lang.NullPointerException
    at com.hp.jmeter.f.jb.a(Unknown Source)
    at com.hp.jmeter.f.a.a(Unknown Source)
    at com.hp.c.a.j.z.run(Unknown Source)
Exception in thread "HPeprofDataFileReaderThread" java.lang.AssertionError: null pointer exception from loader
    at com.hp.jmeter.f.a.a(Unknown Source)
    at com.hp.c.a.j.z.run(Unknown Source)
</code>```

(Why would they obfuscate the bytecode for a free product?!)

Two questions arise from this:

Does anyone know the cause of this HPjmeter error? (EDIT: Yes--see below)

What other tools exist to read hprof files? And why are there none from Sun (are there)?

I know the Eclipse TPTP and other tools can monitor JVMTI data on the fly, but I need a solution that can process the generated hprof files after the fact since the deployed machine only has a JRE (not a JDK) intalled.

EDIT: A very helpful HPjmeter developer replied to my question on an HP ITRC forum indicating that heap=dump needs to be included in the -agentlib options temporarily until a bug in HPjmeter is fixed. This information makes HPjmeter viable again, but I will still leave the question open to see if anyone knows of any other tools.

EDIT: As of version 4.0.00 of HPjmeter (available 05/2009) this bug has been fixed.

答: Your Kit Java Profiler is able to read hprof snapshots (I am not sure if only for memory profiling or for CPU as well). It is not free but is by far the best java profiler I ever used. It presents the results in a clear, intuitive way and performs well on large data sets. The documentation is also pretty good.</p>

OwnerDisplayName: David Citron

ContentLicense: CC BY-SA 2.5

Body:
What tools are available to view the output of the built-in JVM profiler? For example, I'm starting my JVM with:

-agentlib:hprof=cpu=times,thread=y,cutoff=0,format=a,file=someFile.hprof.txt

This generates output in the hprof ("JAVA PROFILE 1.0.1") format.

I have had success in the past using HPjmeter to view these output files in a reasonable way. However, for whatever reason the files that are generated using the current version of the Sun JVM fail to load in the current version of HPjmeter:

java.lang.NullPointerException
    at com.hp.jmeter.f.jb.a(Unknown Source)
    at com.hp.jmeter.f.a.a(Unknown Source)
    at com.hp.c.a.j.z.run(Unknown Source)
Exception in thread "HPeprofDataFileReaderThread" java.lang.AssertionError: null pointer exception from loader
    at com.hp.jmeter.f.a.a(Unknown Source)
    at com.hp.c.a.j.z.run(Unknown Source)

(Why would they obfuscate the bytecode for a free product?!)

Two questions arise from this:

Does anyone know the cause of this HPjmeter error? (EDIT: Yes--see below)

What other tools exist to read hprof files? And why are there none from Sun (are there)?

I know the Eclipse TPTP and other tools can monitor JVMTI data on the fly, but I need a solution that can process the generated hprof files after the fact since the deployed machine only has a JRE (not a JDK) intalled.

EDIT: A very helpful HPjmeter developer replied to my question on an HP ITRC forum indicating that heap=dump needs to be included in the -agentlib options temporarily until a bug in HPjmeter is fixed. This information makes HPjmeter viable again, but I will still leave the question open to see if anyone knows of any other tools.

EDIT: As of version 4.0.00 of HPjmeter (available 05/2009) this bug has been fixed.

LastEditorDisplayName: David Citron

OwnerDisplayName: Bogdan


问:
Puppeteer to save image open in the browser
I have a link for a (gif) image, obtained manually via 'open in new tab'. I want Puppeteer to open the image and then save it to a file. If doing it in a normal browser I would click right button and choose 'save' from the context menu. Is there a simple way to perform this action in Puppeteer?</p>

答:
These lines of codes below will save Wikipedia image logo as filename logo.png

```<code>import * as fs from 'fs'
import puppeteer from 'puppeteer'
;(async () => {
    const wikipedia = 'https://www.wikipedia.org/'
    const browser = await puppeteer.launch()
    const page = (await browser.pages())[0]
    const get = await page.goto(wikipedia)
    const image = await page.waitForSelector('img[src][alt="Wikipedia"]')
    const imgURL = await image.evaluate(img => img.getAttribute('src'))
    const pageNew = await browser.newPage()
    const response = await pageNew.goto(wikipedia + imgURL, {timeout: 0, waitUntil: 'networkidle0'})
    const imageBuffer = await response.buffer()
    await fs.promises.writeFile('./logo.png', imageBuffer)
    await page.close()
    await pageNew.close()
    await browser.close()
})()
</code>```

Please select this as the right answer if this help you.

ContentLicense: CC BY-SA 4.0

Body:
These lines of codes below will save Wikipedia image logo as filename logo.png

import * as fs from 'fs'
import puppeteer from 'puppeteer'
;(async () => {
    const wikipedia = 'https://www.wikipedia.org/'
    const browser = await puppeteer.launch()
    const page = (await browser.pages())[0]
    const get = await page.goto(wikipedia)
    const image = await page.waitForSelector('img[src][alt="Wikipedia"]')
    const imgURL = await image.evaluate(img => img.getAttribute('src'))
    const pageNew = await browser.newPage()
    const response = await pageNew.goto(wikipedia + imgURL, {timeout: 0, waitUntil: 'networkidle0'})
    const imageBuffer = await response.buffer()
    await fs.promises.writeFile('./logo.png', imageBuffer)
    await page.close()
    await pageNew.close()
    await browser.close()
})()

Please select this as the right answer if this help you.


问:
Material Button won't cast white elevation shadow on Android 11
I have a Material Button (from Google's Material Components) which can cast black shadow normally. But when I change the shadow color, it won't appear at all. Here's the button's XML portion :

   <com.google.android.material.button.MaterialButton
           android:id="@+id/next"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_marginTop="@dimen/margin_activity_horizontal"
           android:enabled="false"
           android:elevation="8dp"
           android:layout_margin="16dp"
           android:text="@string/setup_next"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintTop_toBottomOf="@id/nickname_entry_wrapper"
           app:layout_constraintLeft_toLeftOf="parent"
           app:layout_constraintRight_toRightOf="parent"
           tools:enabled="true"
           android:textSize="18sp"
           android:textColor="#000000"
           android:backgroundTint="#FFFFFF"
           android:fontFamily="@font/poppins_semibold"
           android:paddingVertical="12dp"
           android:outlineAmbientShadowColor="#FFFFFFFF"
           android:outlineSpotShadowColor="#FFFFFFFF"
           android:outlineProvider="background"
           android:translationZ="8dp"
           />
```

As you can see, outlineAmbientShadowColor and outlineSpotShadowColor are supposed to change the shadow color that results from elevation and Z translation, right ? I tried adding both elevation and Z translation at once but nothing works, the button still has 0 shadow.

The button is a child view of a Constraint Layout that has a black background. As you can see, I even tried using different values for outlineProvider such as bounds or paddedBounds, yet..nothing.

If anyone has experience with these outline attributes, I'd love to have this solved. The problem isn't specific to Android 11 only, I am just saying that I am using Android 11 for testing, since those outline attributes are only available on Android versions later than Oreo.

答:
As Mike M. has mentioned in the comment, those attributes don't really change the color, they just add a little 'tint'.

If you wanna use material buttons with more features, you should take a look at this library :

Github Repo: Carbon by ZieIony

It should fulfill the required objective (casting white shadows) successfully and without issues on all Android APIs.

Body:
I have a Material Button (from Google's Material Components) which can cast black shadow normally. But when I change the shadow color, it won't appear at all. Here's the button's XML portion :

   <com.google.android.material.button.MaterialButton
           android:id="@+id/next"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_marginTop="@dimen/margin_activity_horizontal"
           android:enabled="false"
           android:elevation="8dp"
           android:layout_margin="16dp"
           android:text="@string/setup_next"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintTop_toBottomOf="@id/nickname_entry_wrapper"
           app:layout_constraintLeft_toLeftOf="parent"
           app:layout_constraintRight_toRightOf="parent"
           tools:enabled="true"
           android:textSize="18sp"
           android:textColor="#000000"
           android:backgroundTint="#FFFFFF"
           android:fontFamily="@font/poppins_semibold"
           android:paddingVertical="12dp"
           android:outlineAmbientShadowColor="#FFFFFFFF"
           android:outlineSpotShadowColor="#FFFFFFFF"
           android:outlineProvider="background"
           android:translationZ="8dp"
           />

As you can see, outlineAmbientShadowColor and outlineSpotShadowColor are supposed to change the shadow color that results from elevation and Z translation, right ? I tried adding both elevation and Z translation at once but nothing works, the button still has 0 shadow.

The button is a child view of a Constraint Layout that has a black background. As you can see, I even tried using different values for outlineProvider such as bounds or paddedBounds, yet..nothing.

If anyone has experience with these outline attributes, I'd love to have this solved. The problem isn't specific to Android 11 only, I am just saying that I am using Android 11 for testing, since those outline attributes are only available on Android versions later than Oreo.


问:
docker-compose Error Cannot start service mongo: driver failed programming external connectivity on endpoint
I'm setting up grandnode with mondodb in docker using docker compose.

docker-compose.yml

```<code>    version: "3.6"

    services:
      mongo:
        image: mongo:3.6
        volumes:
          - mongo_data_db:/data/db
          - mongo_data_configdb:/data/configdb
        ports:
          - 27017:27017
      grandnode:
        image: grandnode/grandnode:4.10
        ports:
          - 8080:8080
        depends_on:
          - mongo

    volumes:
      mongo_data_db:
        external: true
      mongo_data_configdb:
        external: true
</code>```

Getting below error while using the docker-compose.

```<code>E:\docker\grandnode>docker-compose up
Creating network "grandnode_default" with the default driver
Creating grandnode_mongo_1 ... error

ERROR: for grandnode_mongo_1 Cannot start service mongo: driver failed programming external connectivity on endpoint grandnode_mongo_1 (1e54342c07b093e32189aad487927f226b3ed0d1b6bdf7413588377b0e99bc2c): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:27017:tcp:172.20.0.2:27017: input/output error

ERROR: for mongo Cannot start service mongo: driver failed programming external connectivity on endpoint grandnode_mongo_1 (1e54342c07b093e32189aad487927f226b3ed0d1b6bdf7413588377b0e99bc2c): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:27017:tcp:172.20.0.2:27017: input/output error
ERROR: Encountered errors while bringing up the project.
</code>```

答:
for Linux user

sudo systemctl stop MongoDB

sudo docker-compose up -d

Body:
I'm setting up grandnode with mondodb in docker using docker compose.

docker-compose.yml

    version: "3.6"

    services:
      mongo:
        image: mongo:3.6
        volumes:
          - mongo_data_db:/data/db
          - mongo_data_configdb:/data/configdb
        ports:
          - 27017:27017
      grandnode:
        image: grandnode/grandnode:4.10
        ports:
          - 8080:8080
        depends_on:
          - mongo

    volumes:
      mongo_data_db:
        external: true
      mongo_data_configdb:
        external: true

Getting below error while using the docker-compose.

E:\docker\grandnode>docker-compose up
Creating network "grandnode_default" with the default driver
Creating grandnode_mongo_1 ... error

ERROR: for grandnode_mongo_1 Cannot start service mongo: driver failed programming external connectivity on endpoint grandnode_mongo_1 (1e54342c07b093e32189aad487927f226b3ed0d1b6bdf7413588377b0e99bc2c): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:27017:tcp:172.20.0.2:27017: input/output error

ERROR: for mongo Cannot start service mongo: driver failed programming external connectivity on endpoint grandnode_mongo_1 (1e54342c07b093e32189aad487927f226b3ed0d1b6bdf7413588377b0e99bc2c): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:27017:tcp:172.20.0.2:27017: input/output error
ERROR: Encountered errors while bringing up the project.


问:
build array of object from tree object
I'm trying to get into javascript's built-in reduce function and with the help of that build objects inside array.
But you can use whatever function or method you want.

Expected output

```<code>[
  { 'team1': [14697807552, 6858384], '2021': [14697807552, 6858384], 'pepsi': [null, null], 'cola': [14697807552, 6858384] },
  { 'team2': [10268029152, 6922128], '2021': [10268029152, 6922128], 'pepsi': [null, 4800], 'cola': [10268029152, 6917328] },
]
</code>```

What I tried to do

I created a function which takes array as an argument and calls reduce for each array's element.

function transform(arr, obj = {}) {
  return arr.reduce((acc, item) => {
    const newObj = {};
    newObj[item.name] = item.metrics;
    acc.push(newObj);

    if (item.children) {
      transform(item.children, newObj);
    }

    return acc;
  }, []);
}
console.log(transform(arr))```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script>
  const arr = [{
      "name": "team1",
      "metrics": [
        14697807552,
        6858384
      ],
      "children": [{
        "name": "2021",
        "metrics": [
          14697807552,
          6858384
        ],
        "children": [{
            "name": "pepsi",
            "metrics": [
              null,
              null
            ]
          },
          {
            "name": "cola",
            "metrics": [
              14697807552,
              6858384
            ]
          }
        ]
      }]
    },
    {
      "name": "team2",
      "metrics": [
        10268029152,
        6922128
      ],
      "children": [{
        "name": "2021",
        "metrics": [
          10268029152,
          6922128
        ],
        "children": [{
            "name": "pepsi",
            "metrics": [
              null,
              4800
            ]
          },
          {
            "name": "cola",
            "metrics": [
              10268029152,
              6917328
            ]
          }
        ]
      }]
    }
  ]
</script></code>```

But it gives me output that I don't want:

```<code>[
  { team1: [ 14697807552, 6858384 ] },
  { team2: [ 10268029152, 6922128 ] }
]
</code>```

If you didn't understand my question or you have question, ask me. Thanks for paying attention!

答:
I have found a bit different solution:)
It is longer than answer from @trincot but also works

const arr = [{"name": "team1","metrics": [14697807552,6858384],"children": [{"name": "2021","metrics": [14697807552,6858384],"children": [{"name": "pepsi","metrics": [null,null]},{"name": "cola","metrics": [14697807552,6858384]}]}]},{"name": "team2","metrics": [10268029152,6922128],"children": [{"name": "2021","metrics": [10268029152,6922128],"children": [{"name": "pepsi","metrics": [null,4800]},{"name": "cola","metrics": [10268029152,6917328]}]}]}];

const handleArr = (list, rez) => {
  list.forEach((item) => {
    rez[item.name] = item.metrics;
    item.children && handleArr(item.children, rez);
  });
};

const handle = (list) => {
  const rezArr = [];
  for (const item of list) {
    const rezObj = { [item.name]: item.metrics };
    item.children && handleArr(item.children, rezObj);
    rezArr.push(rezObj);
  }
  return rezArr;
};

console.log(handle(arr));
```

Title: build array of object from tree object

Body:
I'm trying to get into javascript's built-in reduce function and with the help of that build objects inside array.
But you can use whatever function or method you want.

Expected output

[
  { 'team1': [14697807552, 6858384], '2021': [14697807552, 6858384], 'pepsi': [null, null], 'cola': [14697807552, 6858384] },
  { 'team2': [10268029152, 6922128], '2021': [10268029152, 6922128], 'pepsi': [null, 4800], 'cola': [10268029152, 6917328] },
]

What I tried to do

I created a function which takes array as an argument and calls reduce for each array's element.

function transform(arr, obj = {}) {
  return arr.reduce((acc, item) => {
    const newObj = {};
    newObj[item.name] = item.metrics;
    acc.push(newObj);

    if (item.children) {
      transform(item.children, newObj);
    }

    return acc;
  }, []);
}
console.log(transform(arr))

But it gives me output that I don't want:

[
  { team1: [ 14697807552, 6858384 ] },
  { team2: [ 10268029152, 6922128 ] }
]

If you didn't understand my question or you have question, ask me. Thanks for paying attention!


问:
Convert Form to JSON
I need to take the values of the form and convert it into JSON. Although the fields ‘tickets’, ‘DriverAge’, and ‘PurchaseDateYear’, needs to be converted to a int and the rest would remain a string. My goal is to be able to take data from user input, change the data type on some inputs and put it all into a JSON. What is the best way to go about this.

HTML

```<code><form class="form" id="form" name="form"  action="https://api.leadprosper.io/ingest" method="post" enctype="multipart/form-data" >
            <div id="wizard">
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="FirstName">First Name</label>
                        <input type="hidden" type="number" id="lp_campaign_id" name="lp_campaign_id" value="5848" required>
                        <input type="hidden" type="number" id="lp_supplier_id" name="lp_supplier_id" value="5848" required>
                        <input type="hidden" id="lp_campaign_id" name="lp_key" value="131bvmpb2" required>
                        <input type="text" id="FirstName" name="FirstName" required>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="LastName">Last Name</label>
                        <input type="text" id="LastName" name="LastName" required>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Email">Email</label>
                        <input pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" type="email" id="Email" name="Email"  required>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Phone">phone</label>
                        <input type="phone"  type="text" pattern="^[789]\d{9,9}$" min="1" max="10" id="Phone" Name="Phone" required>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="VehicleYear">Vehicle Year</label>
                        <input pattern="[0-9]{1,15}" type="number" id="VehicleYear" name="VehicleYear" required>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="PurchaseDateMonth">Purchase Date Month</label>
                        <input pattern="[a-zA-z]{1,15}" type="text" id="PurchaseDateMonth" name="PurchaseDateMonth" required placeholder="September">
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="PurchaseDateYear">Purchaes Date Year</label>
                        <input pattern="[0-9]{1,15}" type="number" id="PurchaseDateYear" name="PurchaseDateYear" placeholder="2022" required>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="FinancedLeased">Finance Leased</label>
                        <select type="text" id="FinancedLeased" name="FinancedLeased" placeholder="">
                            <option value="finance">finance</option>
                            <option value="leased">leased</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Goal">Goal</label>
                        <input pattern="[a-zA-Z]{1,15}" type="text" id="Goal" name="Goal" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="DailyDistance">Daily Distance</label>
                        <input pattern="[0-9]{1,15}" type="text" id="DailyDistance" name="DailyDistance" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="YearlyDistance">Yearly Distance</label>
                        <input pattern="[0-9]{1,15}" type="text" id="YearlyDistance" name="YearlyDistance" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="CompCoverage">Company Coverage</label>
                        <select type="text" id="CompCoverage" name="CompCoverage" placeholder="">
                            <option value="yes">yes</option>
                            <option value="no">no</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="CollisionCoverage">Collision Converage</label>
                        <select type="text" id="CollisionCoverage" name="CollisionCoverage" placeholder="">
                            <option value="yes">yes</option>
                            <option value="no">no</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="MaritalStatus">Marital Status</label>
                        <select type="text" id="MaritalStatus" name="MaritalStatus" placeholder="">
                            <option value="single">single</option>
                            <option value="married/common law">married/common law</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label id="dob"for="DOB">Date of Birth</label>
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="DOB" name="DOB" placeholder="yyyy-mm-dd">
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Occupation">Occupation</label>
                        <input patter="[a-zA-Z]{1,15}" type="text" id="Occupation" name="Occupation" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">

                    <div class="form-row">
                        <label for="genGenderder">gender</label>
                        <select type="text" id="Gender"  name="genGenderder" placeholder="">
                            <option value="male">male</option>
                            <option value="female">female</option>
                            <option value='other'>other</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="LicenseClass">Licence Class</label>
                        <select type="text" id="LicenseClass" name="LicenseClass" placeholder="">
                            <option value="class 5">class 5</option>
                            <option value="class 5-1">class 5-1</option>
                            <option value="class 5-2">class 5-2</option>
                            <option value="other">other</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">

                    <div class="form-row">
                        <label for="DriverAge">Driver Age</label>
                        <input pattern="[0-9]{1,15}" type="text" id="DriverAge" name="DriverAge" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="InsuranceCancellation">Insurance Cancellation</label>
                        <select type="text" id="InsuranceCancellation" name="InsuranceCancellation" placeholder="">
                            <option value="no">no</option>
                            <option value="yes">yes</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-4">

                    <div class="form-row">
                        <label for="Suspensions">Suspensions</label>
                        <select type="text" id="Suspensions" name="Suspensions"  placeholder="">
                            <option value="no">no</option>
                            <option value="yes-once">yes once</option>
                            <option value="yes-more">yes more than once
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Claims">claim</label>
                        <select type="text" id="Claims" name="Claims" placeholder="">
                            <option value="no">no</option>
                            <option value="yes">yes</option>
                        </select>
                        <div class="error"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-4">

                    <div class="form-row">
                        <label for="Tickets">Tickets</label>
                        <input pattern="[0-9]{1,10}" type="text" id="Tickets" name="Tickets" placeholder="">
                        <div class="error"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="StartDate">Start Date</label>
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="StartDate" name="StartDate" placeholder="yyyy-mm-dd">
                        <div class="error"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-4">

                <div class="col-md-4">
                    <div class="form-row">
                        <label for="licenceSince">Licence Since</label>
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="text" id="licenceSince"  name="licenceSince"  placeholder="yyyy-mm-dd">
                        <div class="error"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="City">City</label>
                        <input type="text" id="City" name="City" required>
                        <div class="error"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-row">
                            <label for="state">State</label>
                            <input pattern="[a-zA-z]{2}" type="text" id="State" name="State" required>
                            <div class="error"></div>
                        </div>
                    </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-row">
                        <label for="Postal">Postal</label>
                        <input type="text" pattern="[A-za-z0-9]{5}"  id="Postal" name="Postal" required>
                        <div class="error"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="sumbit">
                    <button type="submit" >Submit</button>
                </div>
            </div>
            </div>
        </form>
</code>```

Thank you for any advice.

答:
Run the code, write in the form, and submit it to see the JSON formatted form data.

const submitBtn = document.querySelector('button[type="submit"]');
const form = document.querySelector('form');

submitBtn.addEventListener('click', (e) => {
  e.preventDefault();
  const data = new FormData(form);
  const json = Object.fromEntries(data.entries());
  console.log(json);
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form class="form" id="form" name="form" action="https://api.leadprosper.io/ingest" method="post" enctype="multipart/form-data">
  <div id="wizard">
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="FirstName">First Name</label>
          <input type="hidden" type="number" id="lp_campaign_id" name="lp_campaign_id" value="5848" required />
          <input type="hidden" type="number" id="lp_supplier_id" name="lp_supplier_id" value="5848" required />
          <input type="hidden" id="lp_campaign_id" name="lp_key" value="131bvmpb2" required />
          <input type="text" id="FirstName" name="FirstName" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="LastName">Last Name</label>
          <input type="text" id="LastName" name="LastName" required />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Email">Email</label>
          <input pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" type="email" id="Email" name="Email" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Phone">phone</label>
          <input type="phone" type="text" pattern="^[789]\d{9,9}$" min="1" max="10" id="Phone" name="Phone" required />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="VehicleYear">Vehicle Year</label>
          <input pattern="[0-9]{1,15}" type="number" id="VehicleYear" name="VehicleYear" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="PurchaseDateMonth">Purchase Date Month</label>
          <input pattern="[a-zA-z]{1,15}" type="text" id="PurchaseDateMonth" name="PurchaseDateMonth" required placeholder="September" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="PurchaseDateYear">Purchaes Date Year</label>
          <input pattern="[0-9]{1,15}" type="number" id="PurchaseDateYear" name="PurchaseDateYear" placeholder="2022" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="FinancedLeased">Finance Leased</label>
          <select type="text" id="FinancedLeased" name="FinancedLeased" placeholder="">
            <option value="finance">finance</option>
            <option value="leased">leased</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Goal">Goal</label>
          <input pattern="[a-zA-Z]{1,15}" type="text" id="Goal" name="Goal" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="DailyDistance">Daily Distance</label>
          <input pattern="[0-9]{1,15}" type="text" id="DailyDistance" name="DailyDistance" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="YearlyDistance">Yearly Distance</label>
          <input pattern="[0-9]{1,15}" type="text" id="YearlyDistance" name="YearlyDistance" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="CompCoverage">Company Coverage</label>
          <select type="text" id="CompCoverage" name="CompCoverage" placeholder="">
            <option value="yes">yes</option>
            <option value="no">no</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="CollisionCoverage">Collision Converage</label>
          <select type="text" id="CollisionCoverage" name="CollisionCoverage" placeholder="">
            <option value="yes">yes</option>
            <option value="no">no</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="MaritalStatus">Marital Status</label>
          <select type="text" id="MaritalStatus" name="MaritalStatus" placeholder="">
            <option value="single">single</option>
            <option value="married/common law">married/common law</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label id="dob" for="DOB">Date of Birth</label>
          <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="DOB" name="DOB" placeholder="yyyy-mm-dd" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Occupation">Occupation</label>
          <input patter="[a-zA-Z]{1,15}" type="text" id="Occupation" name="Occupation" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="genGenderder">gender</label>
          <select type="text" id="Gender" name="genGenderder" placeholder="">
            <option value="male">male</option>
            <option value="female">female</option>
            <option value="other">other</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="LicenseClass">Licence Class</label>
          <select type="text" id="LicenseClass" name="LicenseClass" placeholder="">
            <option value="class 5">class 5</option>
            <option value="class 5-1">class 5-1</option>
            <option value="class 5-2">class 5-2</option>
            <option value="other">other</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="DriverAge">Driver Age</label>
          <input pattern="[0-9]{1,15}" type="text" id="DriverAge" name="DriverAge" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="InsuranceCancellation">Insurance Cancellation</label>
          <select type="text" id="InsuranceCancellation" name="InsuranceCancellation" placeholder="">
            <option value="no">no</option>
            <option value="yes">yes</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Suspensions">Suspensions</label>
          <select type="text" id="Suspensions" name="Suspensions" placeholder="">
            <option value="no">no</option>
            <option value="yes-once">yes once</option>
            <option value="yes-more">yes more than once</option>
          </select>

          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Claims">claim</label>
          <select type="text" id="Claims" name="Claims" placeholder="">
            <option value="no">no</option>
            <option value="yes">yes</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Tickets">Tickets</label>
          <input pattern="[0-9]{1,10}" type="text" id="Tickets" name="Tickets" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="StartDate">Start Date</label>
          <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="StartDate" name="StartDate" placeholder="yyyy-mm-dd" />
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="col-md-4">
          <div class="form-row">
            <label for="licenceSince">Licence Since</label>
            <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="text" id="licenceSince" name="licenceSince" placeholder="yyyy-mm-dd" />
            <div class="error"></div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-md-4">
          <div class="form-row">
            <label for="City">City</label>
            <input type="text" id="City" name="City" required />
            <div class="error"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-4">
            <div class="form-row">
              <label for="state">State</label>
              <input pattern="[a-zA-z]{2}" type="text" id="State" name="State" required />
              <div class="error"></div>
            </div>
          </div>
          <div class="row">
            <div class="col-md-4">
              <div class="form-row">
                <label for="Postal">Postal</label>
                <input type="text" pattern="[A-za-z0-9]{5}" id="Postal" name="Postal" required />
                <div class="error"></div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="sumbit">
              <button type="submit">Submit</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</form></code>```

Title: Convert Form to JSON

Body:
I need to take the values of the form and convert it into JSON. Although the fields ‘tickets’, ‘DriverAge’, and ‘PurchaseDateYear’, needs to be converted to a int and the rest would remain a string. My goal is to be able to take data from user input, change the data type on some inputs and put it all into a JSON. What is the best way to go about this.

HTML

<form class="form" id="form" name="form"  action="https://api.leadprosper.io/ingest" method="post" enctype="multipart/form-data" >

                        First Name
                        <input type="hidden" type="number" id="lp_campaign_id" name="lp_campaign_id" value="5848" required>
                        <input type="hidden" type="number" id="lp_supplier_id" name="lp_supplier_id" value="5848" required>
                        <input type="hidden" id="lp_campaign_id" name="lp_key" value="131bvmpb2" required>
                        <input type="text" id="FirstName" name="FirstName" required>

                        Last Name
                        <input type="text" id="LastName" name="LastName" required>

                        Email
                        <input pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" type="email" id="Email" name="Email"  required>

                        phone
                        <input type="phone"  type="text" pattern="^[789]\d{9,9}$" min="1" max="10" id="Phone" Name="Phone" required>

                        Vehicle Year
                        <input pattern="[0-9]{1,15}" type="number" id="VehicleYear" name="VehicleYear" required>

                        Purchase Date Month
                        <input pattern="[a-zA-z]{1,15}" type="text" id="PurchaseDateMonth" name="PurchaseDateMonth" required placeholder="September">

                        Purchaes Date Year
                        <input pattern="[0-9]{1,15}" type="number" id="PurchaseDateYear" name="PurchaseDateYear" placeholder="2022" required>

                        Finance Leased
                        <select type="text" id="FinancedLeased" name="FinancedLeased" placeholder="">
                            <option value="finance">finance</option>
                            <option value="leased">leased</option>
                        </select>

                        Goal
                        <input pattern="[a-zA-Z]{1,15}" type="text" id="Goal" name="Goal" placeholder="">

                        Daily Distance
                        <input pattern="[0-9]{1,15}" type="text" id="DailyDistance" name="DailyDistance" placeholder="">

                        Yearly Distance
                        <input pattern="[0-9]{1,15}" type="text" id="YearlyDistance" name="YearlyDistance" placeholder="">

                        Company Coverage
                        <select type="text" id="CompCoverage" name="CompCoverage" placeholder="">
                            <option value="yes">yes</option>
                            <option value="no">no</option>
                        </select>

                        Collision Converage
                        <select type="text" id="CollisionCoverage" name="CollisionCoverage" placeholder="">
                            <option value="yes">yes</option>
                            <option value="no">no</option>
                        </select>

                        Marital Status
                        <select type="text" id="MaritalStatus" name="MaritalStatus" placeholder="">
                            <option value="single">single</option>
                            <option value="married/common law">married/common law</option>
                        </select>

                        Date of Birth
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="DOB" name="DOB" placeholder="yyyy-mm-dd">

                        Occupation
                        <input patter="[a-zA-Z]{1,15}" type="text" id="Occupation" name="Occupation" placeholder="">

                        gender
                        <select type="text" id="Gender"  name="genGenderder" placeholder="">
                            <option value="male">male</option>
                            <option value="female">female</option>
                            <option value='other'>other</option>
                        </select>

                        Licence Class
                        <select type="text" id="LicenseClass" name="LicenseClass" placeholder="">
                            <option value="class 5">class 5</option>
                            <option value="class 5-1">class 5-1</option>
                            <option value="class 5-2">class 5-2</option>
                            <option value="other">other</option>
                        </select>

                        Driver Age
                        <input pattern="[0-9]{1,15}" type="text" id="DriverAge" name="DriverAge" placeholder="">

                        Insurance Cancellation
                        <select type="text" id="InsuranceCancellation" name="InsuranceCancellation" placeholder="">
                            <option value="no">no</option>
                            <option value="yes">yes</option>
                        </select>

                        Suspensions
                        <select type="text" id="Suspensions" name="Suspensions"  placeholder="">
                            <option value="no">no</option>
                            <option value="yes-once">yes once</option>
                            <option value="yes-more">yes more than once
                        </select>

                        claim
                        <select type="text" id="Claims" name="Claims" placeholder="">
                            <option value="no">no</option>
                            <option value="yes">yes</option>
                        </select>

                        Tickets
                        <input pattern="[0-9]{1,10}" type="text" id="Tickets" name="Tickets" placeholder="">

                        Start Date
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="StartDate" name="StartDate" placeholder="yyyy-mm-dd">

                        Licence Since
                        <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="text" id="licenceSince"  name="licenceSince"  placeholder="yyyy-mm-dd">

                        City
                        <input type="text" id="City" name="City" required>

                            State
                            <input pattern="[a-zA-z]{2}" type="text" id="State" name="State" required>

                        Postal
                        <input type="text" pattern="[A-za-z0-9]{5}"  id="Postal" name="Postal" required>

                    <button type="submit" >Submit</button>

        </form>

Thank you for any advice.

Body:
Run the code, write in the form, and submit it to see the JSON formatted form data.

const submitBtn = document.querySelector('button[type="submit"]');
const form = document.querySelector('form');

submitBtn.addEventListener('click', (e) => {
  e.preventDefault();
  const data = new FormData(form);
  const json = Object.fromEntries(data.entries());
  console.log(json);
});

<form class="form" id="form" name="form" action="https://api.leadprosper.io/ingest" method="post" enctype="multipart/form-data">
  <div id="wizard">
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="FirstName">First Name</label>
          <input type="hidden" type="number" id="lp_campaign_id" name="lp_campaign_id" value="5848" required />
          <input type="hidden" type="number" id="lp_supplier_id" name="lp_supplier_id" value="5848" required />
          <input type="hidden" id="lp_campaign_id" name="lp_key" value="131bvmpb2" required />
          <input type="text" id="FirstName" name="FirstName" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="LastName">Last Name</label>
          <input type="text" id="LastName" name="LastName" required />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Email">Email</label>
          <input pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" type="email" id="Email" name="Email" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Phone">phone</label>
          <input type="phone" type="text" pattern="^[789]\d{9,9}$" min="1" max="10" id="Phone" name="Phone" required />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="VehicleYear">Vehicle Year</label>
          <input pattern="[0-9]{1,15}" type="number" id="VehicleYear" name="VehicleYear" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="PurchaseDateMonth">Purchase Date Month</label>
          <input pattern="[a-zA-z]{1,15}" type="text" id="PurchaseDateMonth" name="PurchaseDateMonth" required placeholder="September" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="PurchaseDateYear">Purchaes Date Year</label>
          <input pattern="[0-9]{1,15}" type="number" id="PurchaseDateYear" name="PurchaseDateYear" placeholder="2022" required />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="FinancedLeased">Finance Leased</label>
          <select type="text" id="FinancedLeased" name="FinancedLeased" placeholder="">
            <option value="finance">finance</option>
            <option value="leased">leased</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Goal">Goal</label>
          <input pattern="[a-zA-Z]{1,15}" type="text" id="Goal" name="Goal" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="DailyDistance">Daily Distance</label>
          <input pattern="[0-9]{1,15}" type="text" id="DailyDistance" name="DailyDistance" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="YearlyDistance">Yearly Distance</label>
          <input pattern="[0-9]{1,15}" type="text" id="YearlyDistance" name="YearlyDistance" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="CompCoverage">Company Coverage</label>
          <select type="text" id="CompCoverage" name="CompCoverage" placeholder="">
            <option value="yes">yes</option>
            <option value="no">no</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="CollisionCoverage">Collision Converage</label>
          <select type="text" id="CollisionCoverage" name="CollisionCoverage" placeholder="">
            <option value="yes">yes</option>
            <option value="no">no</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="MaritalStatus">Marital Status</label>
          <select type="text" id="MaritalStatus" name="MaritalStatus" placeholder="">
            <option value="single">single</option>
            <option value="married/common law">married/common law</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label id="dob" for="DOB">Date of Birth</label>
          <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="DOB" name="DOB" placeholder="yyyy-mm-dd" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Occupation">Occupation</label>
          <input patter="[a-zA-Z]{1,15}" type="text" id="Occupation" name="Occupation" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="genGenderder">gender</label>
          <select type="text" id="Gender" name="genGenderder" placeholder="">
            <option value="male">male</option>
            <option value="female">female</option>
            <option value="other">other</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="LicenseClass">Licence Class</label>
          <select type="text" id="LicenseClass" name="LicenseClass" placeholder="">
            <option value="class 5">class 5</option>
            <option value="class 5-1">class 5-1</option>
            <option value="class 5-2">class 5-2</option>
            <option value="other">other</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="DriverAge">Driver Age</label>
          <input pattern="[0-9]{1,15}" type="text" id="DriverAge" name="DriverAge" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="InsuranceCancellation">Insurance Cancellation</label>
          <select type="text" id="InsuranceCancellation" name="InsuranceCancellation" placeholder="">
            <option value="no">no</option>
            <option value="yes">yes</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Suspensions">Suspensions</label>
          <select type="text" id="Suspensions" name="Suspensions" placeholder="">
            <option value="no">no</option>
            <option value="yes-once">yes once</option>
            <option value="yes-more">yes more than once</option>
          </select>

          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="Claims">claim</label>
          <select type="text" id="Claims" name="Claims" placeholder="">
            <option value="no">no</option>
            <option value="yes">yes</option>
          </select>
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="form-row">
          <label for="Tickets">Tickets</label>
          <input pattern="[0-9]{1,10}" type="text" id="Tickets" name="Tickets" placeholder="" />
          <div class="error"></div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-row">
          <label for="StartDate">Start Date</label>
          <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="datetime" id="StartDate" name="StartDate" placeholder="yyyy-mm-dd" />
          <div class="error"></div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4">
        <div class="col-md-4">
          <div class="form-row">
            <label for="licenceSince">Licence Since</label>
            <input pattern="?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31" type="text" id="licenceSince" name="licenceSince" placeholder="yyyy-mm-dd" />
            <div class="error"></div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-md-4">
          <div class="form-row">
            <label for="City">City</label>
            <input type="text" id="City" name="City" required />
            <div class="error"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-4">
            <div class="form-row">
              <label for="state">State</label>
              <input pattern="[a-zA-z]{2}" type="text" id="State" name="State" required />
              <div class="error"></div>
            </div>
          </div>
          <div class="row">
            <div class="col-md-4">
              <div class="form-row">
                <label for="Postal">Postal</label>
                <input type="text" pattern="[A-za-z0-9]{5}" id="Postal" name="Postal" required />
                <div class="error"></div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="sumbit">
              <button type="submit">Submit</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</form>


问:
How to change an icon for one single file of the specific type?
I know how to change an icon for a whole file type using registry and file type association.
I also know how to change an icon for a separate folder using desktop.ini file.

My questions is whether it is possible to change an icon for one specific file, let's say one.doc file?

I cannot find a way doing it, yet some upload programs seem to be able to change an icon of the currently uploaded file, while all other files of this type stay with the standard icon. How do they do it?

I can accept a solution in any language; VB, C++, C# - anything goes, though C# is preferable.
Thanks

答: If you create a SHORTCUT file to that file, then simply RIGHT click on that SHORTCUT, you get the options to change the ICON.</p>

ContentLicense: CC BY-SA 3.0


问:
How to Define Paths to Frameworks on a Mac in Java?
I am helping to code a stop-motion program that is to be cross platform, and on windows it works great.  For those who do not know, stop motion is just a fancy term for animation. This program allows users to plug in Nikons, Canons, and Webcams into the computer, and have the program display a live view of the scene, and then have the ability to manually control the camera from there. Included is a framework file from canon for the camera, with a path defined as shown

```<code>import com.sun.jna.Native;
initialization and such

public static EdSdkLibrary EDSDK = (EdSdkLibrary) Native.loadLibrary("Macintosh/EDSDK.framework/EDSDK",EdSdkLibrary.class, options);
</code>```

The error is thrown at the "public static int..." saying that the image is not found. I have tried numerous times redefining the path, moving the framework, and using various other frameworks identical to the one I'm using. Remember, this works flawlessly on Windows, but on Mac there is a problem.

Are frameworks different on macs, or are they to be defined differently? I have looked and found no other solutions.

EDIT: Okay, I defined the path and it now has this symbol > with no text next to it. WHat do I do now?

EDIT: It is saying that this % is not a command. Without it, it still fails to work.

答:
Not really an answer, but more information on the same problem, which I'm experiencing myself.

I can add that JNA will find my frameworks if they're in one of the standard public locations an executable looks for its frameworks, i.e.

~/Library/Frameworks - (public frameworks for the use of the current user)

/Library/Frameworks - (public frameworks for the use of any user)

/System/Library/Frameworks - (public system frameworks)

However, If I want my custom framework to be private - i.e. - not discoverable to other processes than my java vm -- then for some reason JNA doesn't do it.

I know MacOS dynamic loader, when trying to locate a library/framework for any normal (native) MacOS process, does NOT start searching the above locations, but first within several standard "private" locations: (also known as rpath search-path)

in the "Frameworks" directory at the same location as the binary from which the process was loaded: e.g. path/to/my/binary/Frameworks/mySDK.framework

in the "Frameworks" directory at the place where dynamic loader loaded the process (in Application bundles, that would be the myApp.app/Contents/Frameworks/mySDK.framework folder.

So, you can usually create a 'Frameworks' directory of your own right next to your binary, and place your framework in it.

However - JNA misses that. I tried to create a "Frameworks" directory within the "Zulu" - in zulu-11.jre/Contents/Home/bin right next to the 'java' binary, and in other places - but JNA won't find in any of them.

I wonder why, and if there is any documentation for that.

The trick of installing a symlink to my custom framework in /Library/Frameworks may serve you, but I cannot allow other processes to find or load my framework.

Body:
I am helping to code a stop-motion program that is to be cross platform, and on windows it works great.  For those who do not know, stop motion is just a fancy term for animation. This program allows users to plug in Nikons, Canons, and Webcams into the computer, and have the program display a live view of the scene, and then have the ability to manually control the camera from there. Included is a framework file from canon for the camera, with a path defined as shown

import com.sun.jna.Native;
initialization and such

public static EdSdkLibrary EDSDK = (EdSdkLibrary) Native.loadLibrary("Macintosh/EDSDK.framework/EDSDK",EdSdkLibrary.class, options);

The error is thrown at the "public static int..." saying that the image is not found. I have tried numerous times redefining the path, moving the framework, and using various other frameworks identical to the one I'm using. Remember, this works flawlessly on Windows, but on Mac there is a problem.

Are frameworks different on macs, or are they to be defined differently? I have looked and found no other solutions.

EDIT: Okay, I defined the path and it now has this symbol > with no text next to it. WHat do I do now?

EDIT: It is saying that this % is not a command. Without it, it still fails to work.


问:
Why is calling file write() method not working?
I have some Python3 code that opens a file in write mode, writes something to it, and then closes the file. The filename is an int. For some reason, the code doesn't work as expected. When I run the f.write() statement, a 6 is printed to the screen. And when I run the f.close() statement, the string that was supposed to be written is printed to the screen.

```<code>>>> f = open(2, 'w')
>>> f.write('FooBar')
6
>>> f.close()
FooBar>>>
>>>
</code>```

I checked the directory that I ran this in and the file (named 2) was not created. Can anyone explain what is going on? I suspect it has to do with the filename being an int, but I'm not sure.

答:
Alternatively to a file name (type str) open also accepts a file descriptor (type int). 2 is the file descriptor of stderr on Linux, so you are opening the standard error stream for writing, so everything you write to that file object will appear in your terminal/console! The reason it appears only after you do file.close() is that by default the write content isn't immediately written to the file but rather kept in a buffer which gets written only when a newline \n is encountered in the write content, and of course when the file is closed. You can force a writeout to file by calling file.flush().

The reason for the 6 you get on screen is that the return value of file.write is always the number of characters that has been written.

In case you wanted to create a file with the name 2 in the current working directory, you need to wrap the 2 in quotes:

>>> f = open("2", 'w')
>>> f.write('FooBar')
6
>>> f.close()
>>>
```

Body:
I have some Python3 code that opens a file in write mode, writes something to it, and then closes the file. The filename is an int. For some reason, the code doesn't work as expected. When I run the f.write() statement, a 6 is printed to the screen. And when I run the f.close() statement, the string that was supposed to be written is printed to the screen.

>>> f = open(2, 'w')
>>> f.write('FooBar')
6
>>> f.close()
FooBar>>>
>>>

I checked the directory that I ran this in and the file (named 2) was not created. Can anyone explain what is going on? I suspect it has to do with the filename being an int, but I'm not sure.


问:
Remove "::before" — CSS

Currently heading of my blogpost on blogger looks like this. So I wanted to remove this "-" like looking element from my blog, which is a ::before. I tried this advice here and used a little ingenuity to added a CSS like so:

div.post-body-container::before{
    content: none;
}
```

And some other variations of the same. Where am I going wrong here?

This is my blog btw if it is needed on which I'm using Soho Neon theme.

答:
Try using content: '' instead.

```<code>div.post-body-container::before {
  content: '';
}
</code>```

Title: Remove "::before" — CSS

Body:
Currently heading of my blogpost on blogger looks like this. So I wanted to remove this "-" like looking element from my blog, which is a ::before. I tried this advice here and used a little ingenuity to added a CSS like so:

div.post-body-container::before{
    content: none;
}

And some other variations of the same. Where am I going wrong here?

This is my blog btw if it is needed on which I'm using Soho Neon theme.

Body:
Try using content: '' instead.

div.post-body-container::before {
  content: '';
}


问:
How to access google drive from compute engine
I haven't used GCE before but was planning on using it for some CPU bound R scripts.

I see that on the network section of pricing it says there is free egress and ingress with google drive.  I don't see any documentation on how to access my google drive from within a GCE.  Is there documentation on this that someone can point me towards?

答:
In addition to the above, My Drive can be accessed in a GCP Linux compute instance via several other tools:
https://itsfoss.com/use-google-drive-linux/

The details of how the access is performed varies, but the end result is that My Drive will essentially appear in your Linux file system.

Be careful, however, because these programs may have bugs that can delete everything in My Drive (I had this happen with InSync -- I did the trial run then uninstalled and deleted the InSync folder, then later re-installed.  After re-install InSync saw that the folder was deleted, so it thought I wanted to delete everything in My Drive -- that was a very bad day.)


问:
Mysql near duplicates/partial match/LIKE with alias
My table contains some amount of near duplicates (in the "name" column). For example, record 1: abc; record 2: abc-=?; record 3: town; record 4: ?town; record 5: black^pu; record 6: black==pu, etc. They are not in a consecutive order.

Overall, there are 3 columns: dbid (primary key), name (can be associated with different internal ids), and internal id (can be associated with several names).

So, I would like to find all near duplicates (names) for starters. I am quite sure that it is not the most challenging thing to do but I can't figure out how to do it.

I was thinking about using LIKE pattern:
SELECT A.name AS pl1, A.id AS n1, B.name AS pl2, B.id AS n2
FROM table1 A, table1 B
WHERE A.name LIKE '%B.name%' AND A.id=B.id AND A.dbid<>B.dbid

But from my understanding in this way the clause following LIKE look for exact match of what is inside '' instead of checking the alias. Is there any way to address this issue? Any help will be much appreciated.

答:
According to LIKE properties you can add % wildcard to search values into a field.

So if we have two records in the field "name" that:

Record 1: "Dan"
Record 2: "Dani"

you can execute, to get only first record:

```<code>SELECT name FROM table_name WHERE name LIKE "Dan"
</code>```

you can execute, to get first and second record:

```<code>SELECT name FROM table_name WHERE name LIKE "%Dan%"
</code>```

you can execute, to get second one:

```<code>SELECT name FROM table_name WHERE name LIKE "%Dan&" AND NOT LIKE "Dan"
</code>```

Body:
According to LIKE properties you can add % wildcard to search values into a field.

So if we have two records in the field "name" that:

Record 1: "Dan"
Record 2: "Dani"

you can execute, to get only first record:

SELECT name FROM table_name WHERE name LIKE "Dan"

you can execute, to get first and second record:

SELECT name FROM table_name WHERE name LIKE "%Dan%"

you can execute, to get second one:

SELECT name FROM table_name WHERE name LIKE "%Dan&" AND NOT LIKE "Dan"


问:
Pub failed to rename directory because access was denied
Whenever I run flutter doctor or flutter pub get, I am getting the following error

```<code>Pub failed to rename directory because access was denied.
This may be caused by a virus scanner or having a file in the directory open in another application.
Running "flutter pub get" in flutter_tools...
pub get failed (1; in the directory open in another application.)
</code>```

I have tried some commands, ran the commands in administrator mode, but still getting the same error.

答: I have deactivated my Anti-Virus and it worked for me! - Deactivate Antivirus</p>

Body:
Whenever I run flutter doctor or flutter pub get, I am getting the following error

Pub failed to rename directory because access was denied.
This may be caused by a virus scanner or having a file in the directory open in another application.
Running "flutter pub get" in flutter_tools...
pub get failed (1; in the directory open in another application.)

I have tried some commands, ran the commands in administrator mode, but still getting the same error.


问:
Cannot read properties of undefined - javascript class
I wanted to try mobx for react state management, however, I can't get this to work. I have this simple store for storing just a number called counter. You can increment/decrement it, and increse it by x. I have this file store.js for storing the state:

```<code>import { action, makeObservable, observable } from "mobx";

class CounterStore {
    counter = 0;

    constructor() {
        makeObservable(this, {
            counter: observable,
            increment: action,
            decrement: action,
            increase: action
        });

    }

    increment() {
        this.counter++;
    }

    decrement() {
        this.counter--;
    }

    increase(value) {
        this.counter = this.counter + value;
    }
}

const store = new CounterStore();

export default store;
</code>```

And then I have this component named Counter inside Counter.js, which executes the methods like increment and decrement for the store

```<code>import { useRef } from "react";
import classes from './Counter.module.css'
import store from "../store";

function Counter() {

    const numberInput = useRef();

    const increaseHandler = (event) => {
        event.preventDefault();
        if (numberInput.current.value === ''){
            return;
        }
        store.increase(parseInt(numberInput.current.value))
    };
    return (
        <div>
            <div className={classes.counter}>{store.counter}</div>
            <div className={classes.row}>
                <button className={classes.btn} onClick={store.increment}>Increment</button>
                <button className={classes.btn} onClick={store.decrement}>Decrement</button>
            </div>
            <form className={classes.row} onSubmit={increaseHandler}>
                <button className={classes.btn}>Increase by x</button>
                <input className={classes.input} required="true " type="number" ref={numberInput} />
            </form>

        </div>
    );
}

export default Counter;
</code>```

But when i press the button, I always get

```<code>Uncaught TypeError: Cannot read properties of undefined (reading 'counter') at increment
</code>```

How can the counter possibly be undefined? I already export the instantiated store.

答:
Your function is losing context (this), you need to read about it to understand how it works. You destructured this function from the store and it is not bound to it anymore.

The most common way is to define all actions as arrow functions, like that:

```<code>    // Use arrow function to define methods
    increment = () => {
        this.counter++;
    }

    decrement = () => {
        this.counter--;
    }

    increase = (value) => {
        this.counter = this.counter + value;
    }
</code>```

That way you don't need to worry about the context, it will be automatically bound to the current class.

Body:
I wanted to try mobx for react state management, however, I can't get this to work. I have this simple store for storing just a number called counter. You can increment/decrement it, and increse it by x. I have this file store.js for storing the state:

import { action, makeObservable, observable } from "mobx";

class CounterStore {
    counter = 0;

    constructor() {
        makeObservable(this, {
            counter: observable,
            increment: action,
            decrement: action,
            increase: action
        });

    }

    increment() {
        this.counter++;
    }

    decrement() {
        this.counter--;
    }

    increase(value) {
        this.counter = this.counter + value;
    }
}

const store = new CounterStore();

export default store;

And then I have this component named Counter inside Counter.js, which executes the methods like increment and decrement for the store

import { useRef } from "react";
import classes from './Counter.module.css'
import store from "../store";

function Counter() {

    const numberInput = useRef();

    const increaseHandler = (event) => {
        event.preventDefault();
        if (numberInput.current.value === ''){
            return;
        }
        store.increase(parseInt(numberInput.current.value))
    };
    return (

{store.counter}

                <button className={classes.btn} onClick={store.increment}>Increment</button>
                <button className={classes.btn} onClick={store.decrement}>Decrement</button>

            <form className={classes.row} onSubmit={increaseHandler}>
                <button className={classes.btn}>Increase by x</button>
                <input className={classes.input} required="true " type="number" ref={numberInput} />
            </form>

    );
}

export default Counter;

But when i press the button, I always get

Uncaught TypeError: Cannot read properties of undefined (reading 'counter') at increment

How can the counter possibly be undefined? I already export the instantiated store.

Body:
Your function is losing context (this), you need to read about it to understand how it works. You destructured this function from the store and it is not bound to it anymore.

The most common way is to define all actions as arrow functions, like that:

    // Use arrow function to define methods
    increment = () => {
        this.counter++;
    }

    decrement = () => {
        this.counter--;
    }

    increase = (value) => {
        this.counter = this.counter + value;
    }

That way you don't need to worry about the context, it will be automatically bound to the current class.


问:
Flutter / Android PDF viewer is low quality
I am making a flutter app to view PDF files.

I have tried a bunch of different packages (native_pdf_view, flutter_cached_pdfview, uc_pdfview), and it seems like they all result in a somewhat low-quality render.

When I look at the same file using Google Drive's PDF Viewer, the quality is significantly improved. Is there an antialiasing setting I'm missing somewhere that would improve the PDF rendering performance?

Zoomed in screenshot showing the poor antialiasing with native_pdf_view:

Zoomed in screenshot showing the same file using Google Drive:

Any advice on how to improve the rendering of the PDF would be much appreciated. The relevant section of code for the PdfView widget is below. (If I increase the 'width' and 'height' parameters, the quality looks slightly better, but still nowhere near the quality of Google Drive, yet soon runs out of memory)

```<code>PdfView(
                documentLoader: Center(child: CircularProgressIndicator()),
                pageLoader: Center(child: CircularProgressIndicator()),
                controller: _pdfController,
                renderer: (PdfPage page) => page.render(
                  width: page.width * 2,
                  height: page.height * 2,
                  format: PdfPageFormat.JPEG,
                  backgroundColor: '#FFFFFF',
                ),
              ))
</code>```

Edit: Here is the source PDF file used in these screenshots (although other music PDF files also show the same lower quality rendering):
https://www.free-scores.com/PDF_EN/chopin-frederic-prelude-15-296.pdf

This PDF uses a font to display the music ( https://lilypond.org/doc/v2.18/Documentation/notation/the-feta-font ).

答:
I succeeded to resolve the problem of low quality by increasing the width and the height attributes in page.render and by giving quality a value of 100. Here is a snippet of my code:

```<code>renderer: (PdfPage page) => page.render(
          width: page.width * 5,
          height: page.height * 5,
          format: PdfPageImageFormat.jpeg,
          backgroundColor: '#FFFFFF',
          quality: 100,
        ),
</code>```

Note: use the last version of the native_pdf_view package because format: PdfPageFormat is no longer supported. Now it uses PdfPageImageFormat instead of PdfPageFormat.

Body:
I am making a flutter app to view PDF files.

I have tried a bunch of different packages (native_pdf_view, flutter_cached_pdfview, uc_pdfview), and it seems like they all result in a somewhat low-quality render.

When I look at the same file using Google Drive's PDF Viewer, the quality is significantly improved. Is there an antialiasing setting I'm missing somewhere that would improve the PDF rendering performance?

Zoomed in screenshot showing the poor antialiasing with native_pdf_view:

Zoomed in screenshot showing the same file using Google Drive:

Any advice on how to improve the rendering of the PDF would be much appreciated. The relevant section of code for the PdfView widget is below. (If I increase the 'width' and 'height' parameters, the quality looks slightly better, but still nowhere near the quality of Google Drive, yet soon runs out of memory)

PdfView(
                documentLoader: Center(child: CircularProgressIndicator()),
                pageLoader: Center(child: CircularProgressIndicator()),
                controller: _pdfController,
                renderer: (PdfPage page) => page.render(
                  width: page.width * 2,
                  height: page.height * 2,
                  format: PdfPageFormat.JPEG,
                  backgroundColor: '#FFFFFF',
                ),
              ))

Edit: Here is the source PDF file used in these screenshots (although other music PDF files also show the same lower quality rendering):
https://www.free-scores.com/PDF_EN/chopin-frederic-prelude-15-296.pdf

This PDF uses a font to display the music ( https://lilypond.org/doc/v2.18/Documentation/notation/the-feta-font ).

Body:
I succeeded to resolve the problem of low quality by increasing the width and the height attributes in page.render and by giving quality a value of 100. Here is a snippet of my code:

renderer: (PdfPage page) => page.render(
          width: page.width * 5,
          height: page.height * 5,
          format: PdfPageImageFormat.jpeg,
          backgroundColor: '#FFFFFF',
          quality: 100,
        ),

Note: use the last version of the native_pdf_view package because format: PdfPageFormat is no longer supported. Now it uses PdfPageImageFormat instead of PdfPageFormat.


问:
Finding the maximum height of left and right subtree
I would like to implement the following function:

```<code>    def get_height(root, d):

        if root.left:
            left = get_height(root.left, d + 1)
        if root.right:
            right = get_height(root.right, d + 1)

</code>```

The idea is simple: For a given node, I want the maximum height of its left and right subtree. The code is not finished yet obviously. I am looking for a clean way to finish the code above, so the return value is the max. height of the left and right subtree.

答:
To just complete the method, you need to add a return and ensure that the base case works. The base case is when the node is a leaf. So you need to give default values for left and right:

def get_height(root, d):
    left = d
    right = d
    if root.left:
        left = get_height(root.left, d + 1)
    if root.right:
        right = get_height(root.right, d + 1)
    return max(left, right)
```
<p>This is however not the best practice. You should avoid the extra <code>d</code> parameter. You can do without, and let each call return the height of <em>that</em> node, without having to know anything about the parent. When the recursive call is made, the <em>caller</em> can add 1 to the <em>returned</em> value:</p>
<pre class="lang-py prettyprint-override"><code>def get_height(root):
    left = 0
    right = 0
    if root.left:
        left = get_height(root.left) + 1
    if root.right:
        right = get_height(root.right) + 1
    return max(left, right)
</code>```

You can also move the base case one step further, so only one if is needed:

def get_height(root):
    if not root:
        return -1
    return max(get_height(root.left), get_height(root.right)) + 1
```

Body:
I would like to implement the following function:

    def get_height(root, d):

        if root.left:
            left = get_height(root.left, d + 1)
        if root.right:
            right = get_height(root.right, d + 1)

The idea is simple: For a given node, I want the maximum height of its left and right subtree. The code is not finished yet obviously. I am looking for a clean way to finish the code above, so the return value is the max. height of the left and right subtree.

Body:
To just complete the method, you need to add a return and ensure that the base case works. The base case is when the node is a leaf. So you need to give default values for left and right:

def get_height(root, d):
    left = d
    right = d
    if root.left:
        left = get_height(root.left, d + 1)
    if root.right:
        right = get_height(root.right, d + 1)
    return max(left, right)

This is however not the best practice. You should avoid the extra d parameter. You can do without, and let each call return the height of that node, without having to know anything about the parent. When the recursive call is made, the caller can add 1 to the returned value:

def get_height(root):
    left = 0
    right = 0
    if root.left:
        left = get_height(root.left) + 1
    if root.right:
        right = get_height(root.right) + 1
    return max(left, right)

You can also move the base case one step further, so only one if is needed:

def get_height(root):
    if not root:
        return -1
    return max(get_height(root.left), get_height(root.right)) + 1


问:
How to find a missing number from a list?
How do I find the missing number from a sorted list the pythonic way?

```<code>a=[1,2,3,4,5,7,8,9,10]
</code>```

I have come across this post but is there a more and efficient way to do this?

答:
```<code>L=[-5,1,2,3,4,5,7,8,9,10,13,55]

missing=[]

for i in range(L[0],L[-1]):
    if i not in L:
        missing.append(i)
print(missing)
</code>```

Body:
How do I find the missing number from a sorted list the pythonic way?

a=[1,2,3,4,5,7,8,9,10]

I have come across this post but is there a more and efficient way to do this?


问:
Azure Pipeline - YAML how to unzip a downloaded secure file and then execute an exe
I have an Azure Pipeline using a YAML that has one task that downloads a zipped secure file:

```<code>- task: DownloadSecureFile@1
  displayName: Download Testpipelineapp
  name: testPipelineapp
  inputs:
    secureFile: TestPipelineapp.zip
</code>```

The download happens perfectly, but then I need to extract the contents because inside is an .EXE that I need to execute.

Any clue on how can I do this? I'm new to YAML and Azure Devops.

答:
I found how:

```<code>- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Agent.TempDirectory)/TestPipelineapp.zip'
    cleanDestinationFolder: false
    overwriteExistingFiles: true
</code>```

Then in order to execute the .EXE file I had to add a CMD script task

```<code>- task: CmdLine@2
  inputs:
    script: TestPipelineapp.exe
</code>```

Body:
I have an Azure Pipeline using a YAML that has one task that downloads a zipped secure file:

- task: DownloadSecureFile@1
  displayName: Download Testpipelineapp
  name: testPipelineapp
  inputs:
    secureFile: TestPipelineapp.zip

The download happens perfectly, but then I need to extract the contents because inside is an .EXE that I need to execute.

Any clue on how can I do this? I'm new to YAML and Azure Devops.

Body:
I found how:

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Agent.TempDirectory)/TestPipelineapp.zip'
    cleanDestinationFolder: false
    overwriteExistingFiles: true

Then in order to execute the .EXE file I had to add a CMD script task

- task: CmdLine@2
  inputs:
    script: TestPipelineapp.exe


问:
How to make .exe file smaller and faster with pyinstaller (or any other tool)?
I recently made a small desktop app with Tkinter and created a .exe file with pyinstaller (pyinstaller --onefile -w <file-name>) and had to change some things I was doing in the underlying code to make the .exe file smaller.

At the beginning I was using OpenCV to get some frame information from videos (an overkill, I know), which made the .exe file 400 MB in size, mostly because of the use of pandas. So I changed that to python-ffmpeg. This changed a lot and made the file 16MB. But this is still too big compared to other big program exe files, and takes a couple of seconds to start. I'm working with a conda environment that I created only with Python, and other packages/modules I installed in it are XlsxWriter and docx.

答:
You can reduce the file size for pyinstaller by creating the build in a separate virtual environment.

Execute python -m venv demo_env in your cmd to create a new virtual environment.

After that, install all the packages you need for your script, including pyinstaller.

Once you installed everything again, build the exe as before.