问:
javascript map and join on an array
```<code>d = [
    ["a", "Adobe"]
    ["b", "Boston"]
    ["c", "Cars"]
    ["d", "Dominos"]
    ["e", "Microsoft"]
]
const asString = d.map(function(x){
        x[0],'=',x[1]
    }).join('&');
  console.log(asString);
</code>```

I'm trying to generate a query string from the above array, but seem to be getting only &&&&. The original solution used Template Literals and was like this:

```<code>const asString = d
      .map(x => `${encodeURIComponent(x[0])}=${encodeURIComponent(x[1])}`)
      .join('&');
  console.log(asString);
</code>```

This works fine, but I don't want to use Template Literals.

The end result is a querystring like this: a=Adobe&b=Boston&c=Cars&d=Dominos&e=Microsoft

答:
You could take the key and value and return the new strings.

const
    d = [["a", "Adobe Photoshop"], ["b", "Boston"], ["c", "Cars"], ["d", "Dominos"], ["e", "Microsoft"]],
    asString = d.map(([key, value]) => key + '=' + encodeURIComponent(value)).join('&');

console.log(asString);```

Title: javascript map and join on an array

Body:
d = [
    ["a", "Adobe"]
    ["b", "Boston"]
    ["c", "Cars"]
    ["d", "Dominos"]
    ["e", "Microsoft"]
]
const asString = d.map(function(x){
        x[0],'=',x[1]
    }).join('&');
  console.log(asString);

I'm trying to generate a query string from the above array, but seem to be getting only &&&&. The original solution used Template Literals and was like this:

const asString = d
      .map(x => `${encodeURIComponent(x[0])}=${encodeURIComponent(x[1])}`)
      .join('&');
  console.log(asString);

This works fine, but I don't want to use Template Literals.

The end result is a querystring like this: a=Adobe&b=Boston&c=Cars&d=Dominos&e=Microsoft


来源: stackexchange

问:
my button layout is not on the navigation link in website
This is the image i am a learner in html and css this is my first project and i have been battling with a particular problem about buttons on the main page i created the link and name for the buttons when it got to the button layout for designing the button the layout went sideways and i have tried everything i had known

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: #fff;
    color: #555;
    font-family: 'Lato', sans-serif;
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
}

.row {
    width: 1140px;
    margin: 0 auto;
}

header {
    background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img/hero.jpg);
    background-size:cover;
    background-position: center;
    height: 100vh;
}

.hero-text-box {
    position: absolute;
    width: 1140px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

h1 {
    margin: 0;
    color: #fff;
    font-size: 200%;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 1px;
    word-spacing: 4px;
}

.btn {
    display: inline-block;
    margin: 1em 0;
    padding:1em 1.5em;
    background-color: #404040;
    color:#fff;
    text-decoration: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
  <head>
      <link rel="stylesheet" type="text/css" href="Vendors/css/normalize.css">
      <link rel="stylesheet" type="text/css" href="Vendors/css/grid.css">
      <link rel="stylesheet" type="text/css" href="Resources/css/style.css">
      <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" rel="stylesheet">

      <title>Omnifood</title>
  </head>

  <body>
    <header>
      <div class="hero-text-box" >
        <h1>Goodbye junk food.<br>Hello super healthy meals.</h1>
        I’m hungry
        Show me more
      </div>
    </header>
  </body>
</html></code>```

]2

答:
Was this something you had in mind?

I removed .row (not needed) and .hero-text-box (messed up the design with a fixed width). I placed .hero-text-box in the middle with display: flex on header instead. I also added a padding to header that changes depending on the screen width.

You can see the rest of the changes in the code below.

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: #fff;
    color: #555;
    font-family: 'Lato', sans-serif;
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
}

/*.row {
    width: 1140px;
    margin: 0 auto;
}*/

header {
    background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url("https://i.picsum.photos/id/835/300/200.jpg");
    background-size:cover;
    background-position: center;
    height: 100vh;

    /* added new code below */
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 5vw;
}

/*.hero-text-box {
    position: absolute;
    width: 1140px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}*/

h1 {
    margin: 0;
    margin-bottom: 1.5rem; /* added this line */
    color: #fff;
    font-size: 200%;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 1px;
    word-spacing: 4px;
}

.btn {
    display: inline-block;
    margin-right: 1rem;  /* changed this line */
    padding: 1em 1.5em;  /* changed this line */
    background-color: #404040;
    color:#fff;
    text-decoration: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
  <head>
      <link rel="stylesheet" type="text/css" href="Vendors/css/normalize.css">
      <link rel="stylesheet" type="text/css" href="Vendors/css/grid.css">
      <link rel="stylesheet" type="text/css" href="Resources/css/style.css">
      <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" rel="stylesheet">

      <title>Omnifood</title>
  </head>

  <body>
    <header>
      <div class="hero-text-box" >
        <h1>Goodbye junk food.<br>Hello super healthy meals.</h1>
        I’m hungry
        Show me more
      </div>
    </header>
  </body>
</html></code>```

ContentLicense: CC BY-SA 4.0

Body:
This is the image i am a learner in html and css this is my first project and i have been battling with a particular problem about buttons on the main page i created the link and name for the buttons when it got to the button layout for designing the button the layout went sideways and i have tried everything i had known

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: #fff;
    color: #555;
    font-family: 'Lato', sans-serif;
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
}

.row {
    width: 1140px;
    margin: 0 auto;
}

header {
    background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img/hero.jpg);
    background-size:cover;
    background-position: center;
    height: 100vh;
}

.hero-text-box {
    position: absolute;
    width: 1140px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

h1 {
    margin: 0;
    color: #fff;
    font-size: 200%;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 1px;
    word-spacing: 4px;
}

.btn {
    display: inline-block;
    margin: 1em 0;
    padding:1em 1.5em;
    background-color: #404040;
    color:#fff;
    text-decoration: none;
}

<!DOCTYPE html>

      <link rel="stylesheet" type="text/css" href="Vendors/css/normalize.css">
      <link rel="stylesheet" type="text/css" href="Vendors/css/grid.css">
      <link rel="stylesheet" type="text/css" href="Resources/css/style.css">
      <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" rel="stylesheet">

      <title>Omnifood</title>

Goodbye junk food.
Hello super healthy meals.

        I’m hungry
        Show me more

]2

Body:
Was this something you had in mind?

I removed .row (not needed) and .hero-text-box (messed up the design with a fixed width). I placed .hero-text-box in the middle with display: flex on header instead. I also added a padding to header that changes depending on the screen width.

You can see the rest of the changes in the code below.

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: #fff;
    color: #555;
    font-family: 'Lato', sans-serif;
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
}

/*.row {
    width: 1140px;
    margin: 0 auto;
}*/

header {
    background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url("https://i.picsum.photos/id/835/300/200.jpg");
    background-size:cover;
    background-position: center;
    height: 100vh;

    /* added new code below */
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 5vw;
}

/*.hero-text-box {
    position: absolute;
    width: 1140px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}*/

h1 {
    margin: 0;
    margin-bottom: 1.5rem; /* added this line */
    color: #fff;
    font-size: 200%;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 1px;
    word-spacing: 4px;
}

.btn {
    display: inline-block;
    margin-right: 1rem;  /* changed this line */
    padding: 1em 1.5em;  /* changed this line */
    background-color: #404040;
    color:#fff;
    text-decoration: none;
}

<!DOCTYPE html>
<html lang="en">
  <head>
      <link rel="stylesheet" type="text/css" href="Vendors/css/normalize.css">
      <link rel="stylesheet" type="text/css" href="Vendors/css/grid.css">
      <link rel="stylesheet" type="text/css" href="Resources/css/style.css">
      <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" rel="stylesheet">

      <title>Omnifood</title>
  </head>

  <body>
    <header>
      <div class="hero-text-box" >
        <h1>Goodbye junk food.<br>Hello super healthy meals.</h1>
        <a class="btn btn-full" href="#">I’m hungry</a>
        <a class="btn btn-ghost" href="#">Show me more</a>
      </div>
    </header>
  </body>
</html>


答:
You're not returning any values from your map callback:

```<code>d.map(function(x){
        x[0],'=',x[1]
    }).join('&');
</code>```

should be:

```<code>d.map(function(x){
        return x[0] + '=' + x[1]
    }).join('&');
</code>```

"Classic" style functions don't return values in the same way as lambda (arrow) functions do, so you need to explicitly return the value.

Title: javascript map and join on an array

Body:
You're not returning any values from your map callback:

d.map(function(x){
        x[0],'=',x[1]
    }).join('&');

should be:

d.map(function(x){
        return x[0] + '=' + x[1]
    }).join('&');

"Classic" style functions don't return values in the same way as lambda (arrow) functions do, so you need to explicitly return the value.


问:
Make dashed line in Unity 2D like in Blender
I'd like to draw dashed line in Unity with in 2D game like in Blender when you hit B for box select mode.

I tried out lot of tutorials on internet, but nothing seems to work for me.
I'm using Unity 2019.3.0f3 and C#.
Thanks for your help.

答: I think you can create a new material with dashed texture and use Transparent diffuse shader and then use it as line renderer material</p>


问:
How to export fast.ai model from Jupyter Notebook hosted on external server(google cloud compute instance)?
I currently using fast.ai to create machine learning models that classify images. I am using Jupyter Notebook to do my training and it is hosted on a GCP instance that I created.

Currently, I have finished training my model and whatnot, and I am ready to export it out of Jupyter Notebook so I can use it locally on a python file to do some image classification using predict().

```<code>hard_model = cnn_learner(data, models.resnet34, metrics=error_rate)
hard_model.fit_one_cycle(5)
</code>```

So I added this line:

```<code>hard_model.export
</code>```

When executed, the line above returns the chunk below. However, I can neither find a .pkl file (the intended output from the export) on my Jupyter Notebook directories nor locally in Finder.

So for one, am I exporting my model correctly, and more importantly, how do I export a file out from Jupyter Notebook into my local files?

```<code>
Train: LabelList (800 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
light,light,light,light,light
Path: data/categories;

Valid: LabelList (200 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
ballsports,felines,felines,esports,water
Path: data/categories;

Test: None, model=Sequential(
  (0): Sequential(
    (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
    (4): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (1): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (3): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (6): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (3): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (4): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (5): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (7): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (1): Sequential(
    (0): AdaptiveConcatPool2d(
      (ap): AdaptiveAvgPool2d(output_size=1)
      (mp): AdaptiveMaxPool2d(output_size=1)
    )
    (1): Flatten()
    (2): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (3): Dropout(p=0.25, inplace=False)
    (4): Linear(in_features=1024, out_features=512, bias=True)
    (5): ReLU(inplace=True)
    (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (7): Dropout(p=0.5, inplace=False)
    (8): Linear(in_features=512, out_features=10, bias=True)
  )
), opt_func=functools.partial(<class 'torch.optim.adam.Adam'>, betas=(0.9, 0.99)), loss_func=FlattenedLoss of CrossEntropyLoss(), metrics=[<function error_rate at 0x7f6fcb3c83b0>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('data/categories'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[], layer_groups=[Sequential(
  (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (2): ReLU(inplace=True)
  (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
  (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (5): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (6): ReLU(inplace=True)
  (7): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (8): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (9): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (10): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (11): ReLU(inplace=True)
  (12): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (13): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (14): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (15): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (16): ReLU(inplace=True)
  (17): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (18): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (19): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (20): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (21): ReLU(inplace=True)
  (22): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (23): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (24): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (25): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (26): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (27): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (28): ReLU(inplace=True)
  (29): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (30): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (31): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (32): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (33): ReLU(inplace=True)
  (34): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (35): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (36): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (37): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (38): ReLU(inplace=True)
  (39): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (40): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
), Sequential(
  (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (2): ReLU(inplace=True)
  (3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (4): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (5): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (6): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (7): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (8): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (9): ReLU(inplace=True)
  (10): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (11): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (12): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (13): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (14): ReLU(inplace=True)
  (15): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (16): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (17): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (18): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (19): ReLU(inplace=True)
  (20): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (21): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (22): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (23): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (24): ReLU(inplace=True)
  (25): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (26): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (27): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (28): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (29): ReLU(inplace=True)
  (30): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (31): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (32): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (33): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (34): ReLU(inplace=True)
  (35): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (36): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (37): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (38): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (39): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (40): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (41): ReLU(inplace=True)
  (42): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (43): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (44): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (45): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (46): ReLU(inplace=True)
  (47): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (48): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
), Sequential(
  (0): AdaptiveAvgPool2d(output_size=1)
  (1): AdaptiveMaxPool2d(output_size=1)
  (2): Flatten()
  (3): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (4): Dropout(p=0.25, inplace=False)
  (5): Linear(in_features=1024, out_features=512, bias=True)
  (6): ReLU(inplace=True)
  (7): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (8): Dropout(p=0.5, inplace=False)
  (9): Linear(in_features=512, out_features=10, bias=True)
)], add_time=True, silent=False)>

</code>```

答: joblib works very well for this. See this introductory post for details: https://machinelearningmastery.com/save-load-machine-learning-models-python-scikit-learn/

Body:
I currently using fast.ai to create machine learning models that classify images. I am using Jupyter Notebook to do my training and it is hosted on a GCP instance that I created.

Currently, I have finished training my model and whatnot, and I am ready to export it out of Jupyter Notebook so I can use it locally on a python file to do some image classification using predict().

hard_model = cnn_learner(data, models.resnet34, metrics=error_rate)
hard_model.fit_one_cycle(5)

So I added this line:

hard_model.export

When executed, the line above returns the chunk below. However, I can neither find a .pkl file (the intended output from the export) on my Jupyter Notebook directories nor locally in Finder.

So for one, am I exporting my model correctly, and more importantly, how do I export a file out from Jupyter Notebook into my local files?

Train: LabelList (800 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
light,light,light,light,light
Path: data/categories;

Valid: LabelList (200 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
ballsports,felines,felines,esports,water
Path: data/categories;

Test: None, model=Sequential(
  (0): Sequential(
    (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
    (4): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (1): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (3): BasicBlock(
        (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (6): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (3): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (4): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (5): BasicBlock(
        (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (7): Sequential(
      (0): BasicBlock(
        (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (downsample): Sequential(
          (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
          (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
      )
      (1): BasicBlock(
        (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (2): BasicBlock(
        (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        (relu): ReLU(inplace=True)
        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (1): Sequential(
    (0): AdaptiveConcatPool2d(
      (ap): AdaptiveAvgPool2d(output_size=1)
      (mp): AdaptiveMaxPool2d(output_size=1)
    )
    (1): Flatten()
    (2): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (3): Dropout(p=0.25, inplace=False)
    (4): Linear(in_features=1024, out_features=512, bias=True)
    (5): ReLU(inplace=True)
    (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (7): Dropout(p=0.5, inplace=False)
    (8): Linear(in_features=512, out_features=10, bias=True)
  )
), opt_func=functools.partial(<class 'torch.optim.adam.Adam'>, betas=(0.9, 0.99)), loss_func=FlattenedLoss of CrossEntropyLoss(), metrics=[<function error_rate at 0x7f6fcb3c83b0>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('data/categories'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[], layer_groups=[Sequential(
  (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (2): ReLU(inplace=True)
  (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
  (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (5): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (6): ReLU(inplace=True)
  (7): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (8): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (9): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (10): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (11): ReLU(inplace=True)
  (12): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (13): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (14): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (15): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (16): ReLU(inplace=True)
  (17): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (18): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (19): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (20): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (21): ReLU(inplace=True)
  (22): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (23): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (24): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (25): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (26): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (27): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (28): ReLU(inplace=True)
  (29): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (30): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (31): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (32): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (33): ReLU(inplace=True)
  (34): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (35): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (36): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (37): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (38): ReLU(inplace=True)
  (39): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (40): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
), Sequential(
  (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (2): ReLU(inplace=True)
  (3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (4): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (5): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (6): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (7): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (8): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (9): ReLU(inplace=True)
  (10): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (11): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (12): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (13): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (14): ReLU(inplace=True)
  (15): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (16): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (17): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (18): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (19): ReLU(inplace=True)
  (20): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (21): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (22): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (23): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (24): ReLU(inplace=True)
  (25): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (26): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (27): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (28): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (29): ReLU(inplace=True)
  (30): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (31): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (32): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
  (33): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (34): ReLU(inplace=True)
  (35): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (36): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (37): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
  (38): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (39): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (40): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (41): ReLU(inplace=True)
  (42): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (43): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (44): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (45): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (46): ReLU(inplace=True)
  (47): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
  (48): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
), Sequential(
  (0): AdaptiveAvgPool2d(output_size=1)
  (1): AdaptiveMaxPool2d(output_size=1)
  (2): Flatten()
  (3): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (4): Dropout(p=0.25, inplace=False)
  (5): Linear(in_features=1024, out_features=512, bias=True)
  (6): ReLU(inplace=True)
  (7): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (8): Dropout(p=0.5, inplace=False)
  (9): Linear(in_features=512, out_features=10, bias=True)
)], add_time=True, silent=False)>


问:
Automatically tick checkbox when clicking on another form input field
I'm trying to have a checkbox next to a form text-input field. The checkbox can be ticked on/off normally, however when clicking on the text-input field, the checkbox should be automatically ticked as well.

I tried this with putting the text-input inside the label for the checkbox, but it doesn't work. It works fine when I use normal text instead of the input-field:

```<code><input type="checkbox" id="box">
<label for="box">
  <input type="text">
</label>
</code>```

How can I achieve this with HTML/JS? I'm working in the context of a VueJS plugin.

答:
You can do this easily by setting an onclick attribute on text field like:

<input type="checkbox" id="box">

  <input type="text" onclick="box.checked = true">
```

Body:
I'm trying to have a checkbox next to a form text-input field. The checkbox can be ticked on/off normally, however when clicking on the text-input field, the checkbox should be automatically ticked as well.

I tried this with putting the text-input inside the label for the checkbox, but it doesn't work. It works fine when I use normal text instead of the input-field:

<input type="checkbox" id="box">

  <input type="text">

How can I achieve this with HTML/JS? I'm working in the context of a VueJS plugin.

Body:
You can do this easily by setting an onclick attribute on text field like:

<input type="checkbox" id="box">
<label for="box">
  <input type="text" onclick="box.checked = true">
</label>


答:
The click action of <input> (focus & start editing) overrides 's, so you'll have to use JS:

document.querySelector('#text').addEventListener('click', ()=>{
  document.querySelector('#box').checked=true
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type="checkbox" id="box">
<input type="text" id="text"></code>```

Title: Automatically tick checkbox when clicking on another form input field

Body:
The click action of <input> (focus & start editing) overrides <label>'s, so you'll have to use JS:

document.querySelector('#text').addEventListener('click', ()=>{
  document.querySelector('#box').checked=true
})

<input type="checkbox" id="box">
<input type="text" id="text">


问:
How to convert JSON string column row into a queryable table
I have exported to BigQuery from Firestore a whole collection to perform certain queries on it.

After the data was populated in my BigQuery console, now I can query the whole set like this

```<code>SELECT *
FROM `myapp-1a602.firestore_orders.orders_raw_changelog`
LIMIT 1000
</code>```

Now, this statement throws my different columns, but the one I'm looking for is the data column, in my data column is each document JSON, but is in json format and I need to query all this values.

Now, this is the data from one row

```<code>{
    "cart": [{
        "qty": 1,
        "description": "Sprite 1 L",
        "productName": "Sprite 1 Liter",
        "price": 1.99,
        "productId": 9
    }],
    "storeName": "My awesome shop",
    "status": 5,
    "timestamp": {
        "_seconds": 1590713204,
        "_nanoseconds": 916000000
    }
}
</code>```

This data is inside the data column, so if I do this

```<code>SELECT data
FROM `myapp-1a602.firestore_orders.orders_raw_changelog`
LIMIT 1000
</code>```

I will get all the json values for each document, but I don't know how to query that values, lets say I want to know all orders with status 5 and shopName My awesome shop , now, I need to do something with this json to convert it into a table ? does I need to perform the query in the json itself ?

How can I query this json output ?

Thanks

答:
I need to do something with this json to convert it into a table ? does I need to perform the query in the json itself ?

Below is for BigQuery Standard SQL

```<code>#standardSQL
SELECT * EXCEPT(data, cart_item),
  JSON_EXTRACT(data, '$.status') AS status,
  JSON_EXTRACT(data, '$.storeName') AS storeName,
  JSON_EXTRACT(cart_item, '$.qty') AS qty,
  JSON_EXTRACT(cart_item, '$.description') AS description,
  JSON_EXTRACT(cart_item, '$.productName') AS productName,
  JSON_EXTRACT(cart_item, '$.price') AS price,
  JSON_EXTRACT(cart_item, '$.productId') AS productId
FROM `project.dataset.table`,
UNNEST(JSON_EXTRACT_ARRAY(data, '$.cart')) cart_item
</code>```

If to apply to sample data from your question as in below example

```<code>#standardSQL
WITH `project.dataset.table` AS (
  SELECT 1 order_id, '''
{
    "cart": [{
        "qty": 1,
        "description": "Sprite 1 L",
        "productName": "Sprite 1 Liter",
        "price": 1.99,
        "productId": 9
    },{
        "qty": 2,
        "description": "Fanta 1 L",
        "productName": "Fanta 1 Liter",
        "price": 1.99,
        "productId": 10
    }],
    "storeName": "My awesome shop",
    "status": 5,
    "timestamp": {
        "_seconds": 1590713204,
        "_nanoseconds": 916000000
    }
}
'''  data
)
SELECT * EXCEPT(data, cart_item),
  JSON_EXTRACT(data, '$.status') AS status,
  JSON_EXTRACT(data, '$.storeName') AS storeName,
  JSON_EXTRACT(cart_item, '$.qty') AS qty,
  JSON_EXTRACT(cart_item, '$.description') AS description,
  JSON_EXTRACT(cart_item, '$.productName') AS productName,
  JSON_EXTRACT(cart_item, '$.price') AS price,
  JSON_EXTRACT(cart_item, '$.productId') AS productId
FROM `project.dataset.table`,
UNNEST(JSON_EXTRACT_ARRAY(data, '$.cart')) cart_item
</code>```

result is

```<code>Row order_id    status  storeName           qty     description     productName         price   productId
1   1           5       "My awesome shop"   1       "Sprite 1 L"    "Sprite 1 Liter"    1.99    9
2   1           5       "My awesome shop"   2       "Fanta 1 L"     "Fanta 1 Liter"     1.99    10
</code>```

Body:
I have exported to BigQuery from Firestore a whole collection to perform certain queries on it.

After the data was populated in my BigQuery console, now I can query the whole set like this

SELECT *
FROM `myapp-1a602.firestore_orders.orders_raw_changelog`
LIMIT 1000

Now, this statement throws my different columns, but the one I'm looking for is the data column, in my data column is each document JSON, but is in json format and I need to query all this values.

Now, this is the data from one row

{
    "cart": [{
        "qty": 1,
        "description": "Sprite 1 L",
        "productName": "Sprite 1 Liter",
        "price": 1.99,
        "productId": 9
    }],
    "storeName": "My awesome shop",
    "status": 5,
    "timestamp": {
        "_seconds": 1590713204,
        "_nanoseconds": 916000000
    }
}

This data is inside the data column, so if I do this

SELECT data
FROM `myapp-1a602.firestore_orders.orders_raw_changelog`
LIMIT 1000

I will get all the json values for each document, but I don't know how to query that values, lets say I want to know all orders with status 5 and shopName My awesome shop , now, I need to do something with this json to convert it into a table ? does I need to perform the query in the json itself ?

How can I query this json output ?

Thanks

Body:
I need to do something with this json to convert it into a table ? does I need to perform the query in the json itself ?

Below is for BigQuery Standard SQL

#standardSQL
SELECT * EXCEPT(data, cart_item),
  JSON_EXTRACT(data, '$.status') AS status,
  JSON_EXTRACT(data, '$.storeName') AS storeName,
  JSON_EXTRACT(cart_item, '$.qty') AS qty,
  JSON_EXTRACT(cart_item, '$.description') AS description,
  JSON_EXTRACT(cart_item, '$.productName') AS productName,
  JSON_EXTRACT(cart_item, '$.price') AS price,
  JSON_EXTRACT(cart_item, '$.productId') AS productId
FROM `project.dataset.table`,
UNNEST(JSON_EXTRACT_ARRAY(data, '$.cart')) cart_item

If to apply to sample data from your question as in below example

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 1 order_id, '''
{
    "cart": [{
        "qty": 1,
        "description": "Sprite 1 L",
        "productName": "Sprite 1 Liter",
        "price": 1.99,
        "productId": 9
    },{
        "qty": 2,
        "description": "Fanta 1 L",
        "productName": "Fanta 1 Liter",
        "price": 1.99,
        "productId": 10
    }],
    "storeName": "My awesome shop",
    "status": 5,
    "timestamp": {
        "_seconds": 1590713204,
        "_nanoseconds": 916000000
    }
}
'''  data
)
SELECT * EXCEPT(data, cart_item),
  JSON_EXTRACT(data, '$.status') AS status,
  JSON_EXTRACT(data, '$.storeName') AS storeName,
  JSON_EXTRACT(cart_item, '$.qty') AS qty,
  JSON_EXTRACT(cart_item, '$.description') AS description,
  JSON_EXTRACT(cart_item, '$.productName') AS productName,
  JSON_EXTRACT(cart_item, '$.price') AS price,
  JSON_EXTRACT(cart_item, '$.productId') AS productId
FROM `project.dataset.table`,
UNNEST(JSON_EXTRACT_ARRAY(data, '$.cart')) cart_item

result is

Row order_id    status  storeName           qty     description     productName         price   productId
1   1           5       "My awesome shop"   1       "Sprite 1 L"    "Sprite 1 Liter"    1.99    9
2   1           5       "My awesome shop"   2       "Fanta 1 L"     "Fanta 1 Liter"     1.99    10


问:
Mysql trigger syntax (IF NOT EXISTS)
We have two tables ( Club, Village )

```<code>Club(id, Name, Location, Village)
Village(id, name)
</code>```

Professor gave us example like this...

```<code>CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
REFERENCING NEW AS uus
FOR EACH ROW
BEGIN
    IF (NOT EXISTS (
        )
        THEN
        )
    END IF;

    UPDATE Club
END;

</code>```

I don't get the syntax idea. I tried to use this example

```<code>CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
REFERENCING NEW AS uus
FOR EACH ROW
BEGIN
    IF uus.Club.Location (NOT EXISTS ( Village.name
        )
        THEN INSERT INTO Village (name) VALUES (uus.Club.location)
        )
    END IF;

    UPDATE Club SET (Village.name = uus.Location)
END;

</code>```

Obviously it's not working, it looks more like a pseudocode...but it should give the idea. How can i fix my code ?

If something is not clear, then I will try to add more information

答:
It's hard to guess what you want since psuedo-code or not the code is nonsense.

some corrections

```<code>CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
FOR EACH ROW
BEGIN
    IF NOT EXISTS (select 1 from Village where name = new.location THEN
       INSERT INTO Village (name) VALUES (new.location)
    else
      #UPDATE Club SET (Village.name = uus.Location)
    end if;
END
</code>```

note - This is mysql syntax , there is no referencing clause, you cannot update CLUB, you may need to set delimiters

Title: Mysql trigger syntax (IF NOT EXISTS)

Body:
We have two tables ( Club, Village )

Club(id, Name, Location, Village)
Village(id, name)

Professor gave us example like this...

CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
REFERENCING NEW AS uus
FOR EACH ROW
BEGIN
    IF (NOT EXISTS (
        )
        THEN
        )
    END IF;

    UPDATE Club
END;

I don't get the syntax idea. I tried to use this example

CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
REFERENCING NEW AS uus
FOR EACH ROW
BEGIN
    IF uus.Club.Location (NOT EXISTS ( Village.name
        )
        THEN INSERT INTO Village (name) VALUES (uus.Club.location)
        )
    END IF;

    UPDATE Club SET (Village.name = uus.Location)
END;

Obviously it's not working, it looks more like a pseudocode...but it should give the idea. How can i fix my code ?

If something is not clear, then I will try to add more information

Body:
It's hard to guess what you want since psuedo-code or not the code is nonsense.

some corrections

CREATE TRIGGER tg_add_club
AFTER INSERT ON Club
FOR EACH ROW
BEGIN
    IF NOT EXISTS (select 1 from Village where name = new.location THEN
       INSERT INTO Village (name) VALUES (new.location)
    else
      #UPDATE Club SET (Village.name = uus.Location)
    end if;
END

note - This is mysql syntax , there is no referencing clause, you cannot update CLUB, you may need to set delimiters


问:
flutter_pdfview crashing device after opening pdf
I wanted to use flutter_pdfview in an app. During debugging everything worked fine, but once i build the app in Release mode I clicked around in the App and opened some PDF and at some pont a PDF does not load, so i got back to the page before, and at this point the touchscreen of my device does not respond any longer. I tetsted it on two devices with the arm64 version, both devices do not respond any longer at some point. However when I open the App on an armeabi device everything is working fine.

The error is: (Unhandled Exception: PlatformException(error, Neither user 10350 nor current process has android.permission.WAKE_LOCK., null)

I am using flutter_pdfview version 1.0.2+2,
my flutter doctor -v is:

```<code>   • Flutter version 1.19.0-2.0.pre.142 at C:\flutter\flutter
   • Framework revision 721927efd3 (7 days ago), 2020-05-21 17:52:02 -0700
   • Engine revision 9ce1e5c5c7
   • Dart version 2.9.0 (build 2.9.0-10.0.dev 7706afbcf5)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
   • Android SDK at C:\Users\Jakob\AppData\Local\Android\sdk
   • Platform android-29, build-tools 29.0.2
   • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
   • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
   • All Android licenses accepted.

[√] Android Studio (version 3.5)
   • Android Studio at C:\Program Files\Android\Android Studio
   • Flutter plugin version 42.1.1
   • Dart plugin version 191.8593
   • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Community Edition (version 2019.3)
   • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4
   X Flutter plugin not installed; this adds Flutter specific functionality.
   X Dart plugin not installed; this adds Dart specific functionality.
   • For information about installing plugins, see
     https://flutter.dev/intellij-setup/#installing-the-plugins

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

[!] Connected device
   ! No devices available

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

答: After some time, I fixed it by adding <uses-permission android:name="android.permission.WAKE_LOCK" /> to AndroidManifest.xml

Body:
I wanted to use flutter_pdfview in an app. During debugging everything worked fine, but once i build the app in Release mode I clicked around in the App and opened some PDF and at some pont a PDF does not load, so i got back to the page before, and at this point the touchscreen of my device does not respond any longer. I tetsted it on two devices with the arm64 version, both devices do not respond any longer at some point. However when I open the App on an armeabi device everything is working fine.

The error is: (Unhandled Exception: PlatformException(error, Neither user 10350 nor current process has android.permission.WAKE_LOCK., null)

I am using flutter_pdfview version 1.0.2+2,
my flutter doctor -v is:

   • Flutter version 1.19.0-2.0.pre.142 at C:\flutter\flutter
   • Framework revision 721927efd3 (7 days ago), 2020-05-21 17:52:02 -0700
   • Engine revision 9ce1e5c5c7
   • Dart version 2.9.0 (build 2.9.0-10.0.dev 7706afbcf5)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
   • Android SDK at C:\Users\Jakob\AppData\Local\Android\sdk
   • Platform android-29, build-tools 29.0.2
   • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
   • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
   • All Android licenses accepted.

[√] Android Studio (version 3.5)
   • Android Studio at C:\Program Files\Android\Android Studio
   • Flutter plugin version 42.1.1
   • Dart plugin version 191.8593
   • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Community Edition (version 2019.3)
   • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4
   X Flutter plugin not installed; this adds Flutter specific functionality.
   X Dart plugin not installed; this adds Dart specific functionality.
   • For information about installing plugins, see
     https://flutter.dev/intellij-setup/#installing-the-plugins

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

[!] Connected device
   ! No devices available

! Doctor found issues in 3 categories.


问:
Get last clicked and stop function
I have a grid that when some cell is clicked, it blinks (thanks to cyclicFade jQuery plugin). I need to stop blink the cell when I click in another one. You can see the complete markup here.

```<code>$(".color").click(function () {
    $("#colorPicker").show();
    var number = $(this).attr('id').substr(1);
    var selected = $(this).attr('class');
    if (selected != 'color selected') {
        $('#n'+numero).css({
            'background-color':'#000',
            'border':'1px solid black',
            'margin-top':'0px',
            'margin-left':'0px'}).attr({'class': "color s"});
        var numeroCelda = Number(Number(numero)+1);
        $('#numero').replaceWith('<span id="numero">'+numeroCelda+'</span>');
     }
     $(this).cyclicFade({params: [
         {fadeout:1000, stayout:80, opout:0, fadein:1000, stayin:80, opin:1.0}]
     });
     return numero;
});
</code>```

How I could know what was the last element clicked and pass it to the function in order to switch cyclicFade off in that specific cell? Something like this:

```<code>$(lastclicked).cyclicFade(stop);
</code>```

Thanks in advance.

答:
In your click handler add:

```<code>$('.lastClicked').cyclicFade(stop);
$('.lastClicked').removeClass('lastClicked');
$(this).addClass('lastClicked');
</code>```

It should be enough.

K

ContentLicense: CC BY-SA 3.0

Title: Get last clicked and stop function

Body:
I have a grid that when some cell is clicked, it blinks (thanks to cyclicFade jQuery plugin). I need to stop blink the cell when I click in another one. You can see the complete markup here.

$(".color").click(function () {
    $("#colorPicker").show();
    var number = $(this).attr('id').substr(1);
    var selected = $(this).attr('class');
    if (selected != 'color selected') {
        $('#n'+numero).css({
            'background-color':'#000',
            'border':'1px solid black',
            'margin-top':'0px',
            'margin-left':'0px'}).attr({'class': "color s"});
        var numeroCelda = Number(Number(numero)+1);
        $('#numero').replaceWith(''+numeroCelda+'');
     }
     $(this).cyclicFade({params: [
         {fadeout:1000, stayout:80, opout:0, fadein:1000, stayin:80, opin:1.0}]
     });
     return numero;
});

How I could know what was the last element clicked and pass it to the function in order to switch cyclicFade off in that specific cell? Something like this:

$(lastclicked).cyclicFade(stop);

Thanks in advance.

Body:
In your click handler add:

$('.lastClicked').cyclicFade(stop);
$('.lastClicked').removeClass('lastClicked');
$(this).addClass('lastClicked');

It should be enough.

K


问:
Scala interning: how does different initialisation affect comparison?
I am new to Scala but I know Java. Thus, as far as I understand, the difference is that == in Scala acts as .equals in Java, which means we are looking for the value; and eq in Scala acts as == in Java, which means we are looking for the reference address and not value.

However, after running the code below:

```<code>    val greet_one_v1 = "Hello"
    val greet_two_v1 = "Hello"
    println(
            (greet_one_v1 == greet_two_v1),
            (greet_one_v1 eq greet_two_v1)
    )

    val greet_one_v2 = new String("Hello")
    val greet_two_v2 = new String("Hello")
    println(
            (greet_one_v2 == greet_two_v2),
            (greet_one_v2 eq greet_two_v2)
    )
</code>```

I get the following output:

```<code>(true,true)
(true,false)
</code>```

My theory is that the initialisation of these strings differs. Hence, how is val greet_one_v1 = "Hello" different from val greet_one_v2 = new String("Hello")? Or, if my theory is incorrect, why do I have different outputs?

答: As correctly answered by Luis Miguel Mejía Suárez, the answer lies in String Interning which is part of what JVM (Java Virtual Machine) does automatically. To initiate a new String it needs to be initiated explicitly like in my example above; otherwise, Java will allocate the same memory for same values for optimisation reasons.</p>

Body:
I am new to Scala but I know Java. Thus, as far as I understand, the difference is that == in Scala acts as .equals in Java, which means we are looking for the value; and eq in Scala acts as == in Java, which means we are looking for the reference address and not value.

However, after running the code below:

    val greet_one_v1 = "Hello"
    val greet_two_v1 = "Hello"
    println(
            (greet_one_v1 == greet_two_v1),
            (greet_one_v1 eq greet_two_v1)
    )

    val greet_one_v2 = new String("Hello")
    val greet_two_v2 = new String("Hello")
    println(
            (greet_one_v2 == greet_two_v2),
            (greet_one_v2 eq greet_two_v2)
    )

I get the following output:

(true,true)
(true,false)

My theory is that the initialisation of these strings differs. Hence, how is val greet_one_v1 = "Hello" different from val greet_one_v2 = new String("Hello")? Or, if my theory is incorrect, why do I have different outputs?


问:
Removing brackets in filenames using Python across different file extensions
I have a few text, pdf, and doc files that have brackets and I wish to remove them in the file names.

For eg. [Alpha].txt --> Alpha.txt

The below code works, but it only works on specifically one file extension. Is there a way to include .pdf and .doc files within the same code?

```<code>import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.txt')

for file_name in files_to_rename:
    file_name_new = file_name.replace('[', '')
    os.rename(file_path + file_name, file_path + file_name_new)
    os.rename(file_path + file_name_new, file_path + file_name_new.replace(']', ''))
</code>```

答:
It's very simple for all files. Just replace '*.txt with *.*. The *.* means any file name with any file extension:

```<code>import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.*') #All files included

for file_name in files_to_rename:
    file_name_new = file_name.replace('[', '')
    os.rename(file_path + file_name, file_path + file_name_new)
    os.rename(file_path + file_name_new, file_path + file_name_new.replace(']', ''))
</code>```

For specific extensions, just combine the lists:

```<code>import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.txt') + fnmatch.filter(os.listdir(file_path), '*.pdf') + fnmatch.filter(os.listdir(file_path), '*.doc')
</code>```

Body:
I have a few text, pdf, and doc files that have brackets and I wish to remove them in the file names.

For eg. [Alpha].txt --> Alpha.txt

The below code works, but it only works on specifically one file extension. Is there a way to include .pdf and .doc files within the same code?

import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.txt')

for file_name in files_to_rename:
    file_name_new = file_name.replace('[', '')
    os.rename(file_path + file_name, file_path + file_name_new)
    os.rename(file_path + file_name_new, file_path + file_name_new.replace(']', ''))

Body:
It's very simple for all files. Just replace '*.txt with *.*. The *.* means any file name with any file extension:

import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.*') #All files included

for file_name in files_to_rename:
    file_name_new = file_name.replace('[', '')
    os.rename(file_path + file_name, file_path + file_name_new)
    os.rename(file_path + file_name_new, file_path + file_name_new.replace(']', ''))

For specific extensions, just combine the lists:

import os, fnmatch

#Set directory of locataion; include double slash for each subfolder.
file_path = "C:\\Users\\Mr.Slowbro\\Desktop\\Source Files\\"

#Set file extension accordingly
files_to_rename = fnmatch.filter(os.listdir(file_path), '*.txt') + fnmatch.filter(os.listdir(file_path), '*.pdf') + fnmatch.filter(os.listdir(file_path), '*.doc')


问:
Django filter request result
I have two models Player and Game

```<code>class Player(models.Model):
    userId = models.CharField(max_length = 150, primary_key=True)
    username = models.CharField(max_length = 250)
    email = models.CharField(max_length = 150)
    playedGames = models.IntegerField()
</code>```

```<code>class Game(models.Model):
    player = models.ForeignKey(Player, on_delete=models.CASCADE)
    date = models.DateTimeField()
    award = models.IntegerField()
</code>```

And request that returns winners list.

```<code>wins = Player.objects.annotate(
    max_award=Max('game__award')
).filter(
    game__award=F('max_award')
).annotate(
    date=F('game__date')
    award=F('game__award')
).values(
    'userId',
    'date',
    'award'
).order_by('-max_award')
</code>```

But there is one bug. If player have 2 or more of the same max Awards with different dates, then in result we get the same number of records (one for each date).
For example:

Alex, 75, 2020-05-29

Alex, 75, 2020-04-23

Richard, 68, 2020-05-27

But I'd like to get list, like this:

Alex, 75, 2020-05-29

Richard, 68, 2020-05-27

How can I get just one record for each user with his max award (with last date)?

答:
use distinct

try this..

```<code>wins = Player.objects.annotate(
    max_award=Max('game__award')
).filter(
    game__award=F('max_award')
).annotate(
    date=F('game__date')
    award=F('game__award')
).values(
    'userId',
    'date',
    'award'
).order_by('-max_award').distinct('game__date')

</code>```

Title: Django filter request result

Body:
I have two models Player and Game

class Player(models.Model):
    userId = models.CharField(max_length = 150, primary_key=True)
    username = models.CharField(max_length = 250)
    email = models.CharField(max_length = 150)
    playedGames = models.IntegerField()

class Game(models.Model):
    player = models.ForeignKey(Player, on_delete=models.CASCADE)
    date = models.DateTimeField()
    award = models.IntegerField()

And request that returns winners list.

wins = Player.objects.annotate(
    max_award=Max('game__award')
).filter(
    game__award=F('max_award')
).annotate(
    date=F('game__date')
    award=F('game__award')
).values(
    'userId',
    'date',
    'award'
).order_by('-max_award')

But there is one bug. If player have 2 or more of the same max Awards with different dates, then in result we get the same number of records (one for each date).
For example:

Alex, 75, 2020-05-29

Alex, 75, 2020-04-23

Richard, 68, 2020-05-27

But I'd like to get list, like this:

Alex, 75, 2020-05-29

Richard, 68, 2020-05-27

How can I get just one record for each user with his max award (with last date)?

Body:
use distinct

try this..

wins = Player.objects.annotate(
    max_award=Max('game__award')
).filter(
    game__award=F('max_award')
).annotate(
    date=F('game__date')
    award=F('game__award')
).values(
    'userId',
    'date',
    'award'
).order_by('-max_award').distinct('game__date')


问:
Storing token on server-side using nestjs
I have a nestjs application that consumes third party API for data. In order to use that third party API, I need to pass along an access token. This access token is application-wide and not attached to any one user.

What would be the best place to store such a token in Nestjs, meeting the following requirements:

It must be available in the application and not per given user

It must not be exposed to the frontend application

It must work in a load balancer setup

I am looking at Nestjs caching https://docs.nestjs.com/techniques/caching, but I am not sure whether that's the best practice and if it is - should I use it with in-memory storage or something like redis.

Thank you.

答: If you're working with Load Balancing, then in-memory solutions are dead on arrival, as they will only affect one instance of your server, not all of them. Your best bet for speed purposes and accessibility would be Redis, saving the token under a simple key and keeping it alive from there (and updating it as necessary). Just make sure all your instances connect to the same Redis instance, and that your instance can handle it, shouldn't be a problem, more of a callout</p>


问:
PowerShell | Get-ChildItem to Function via Pipeline not providing all items
Due to Azure Dev Ops converting LF to CRLF on deployment I have to create a custom function that will search for .sh files and convert them back to how they are stored in the repo (LF). That code I got down fine however I REALLY want to make a awesome function I can do a single get-childitem recursive looking for .sh files and then pipe that to my custom function that will turn them back to the correct format.

My problem is that me, get-childitem, and functions arent not getting along.

To keep this focused on just the main issue here is an over simplistic example function:

```<code>Function List-Items {
    param (
        [Parameter(ValueFromPipeline = $true)]$items
    )

    Write-Output "Item Count: $($items | Measure-Object | select -ExpandProperty Count)"
    foreach ($item in $items) {
        Write-Output "Item: $($item)"
    }
}
</code>```

I call it using:

dir c:\temp\ | List-Items

Yet even though there are clearly 52 items via this command:
dir c:\temp\ | Measure-Object

The function only sees the last record of those 52. How do I access all 52 within my custom list-items function?

答:
You need a process block that runs once for each item piped.</p>

```<code>function hi {
  param([Parameter(ValueFromPipeline=$True)]$inputvalue)

  process {
    $inputvalue.count
  }

}

1,2,3 | hi

1
1
1

</code>```

Body:
Due to Azure Dev Ops converting LF to CRLF on deployment I have to create a custom function that will search for .sh files and convert them back to how they are stored in the repo (LF). That code I got down fine however I REALLY want to make a awesome function I can do a single get-childitem recursive looking for .sh files and then pipe that to my custom function that will turn them back to the correct format.

My problem is that me, get-childitem, and functions arent not getting along.

To keep this focused on just the main issue here is an over simplistic example function:

Function List-Items {
    param (
        [Parameter(ValueFromPipeline = $true)]$items
    )

    Write-Output "Item Count: $($items | Measure-Object | select -ExpandProperty Count)"
    foreach ($item in $items) {
        Write-Output "Item: $($item)"
    }
}

I call it using:

dir c:\temp\ | List-Items

Yet even though there are clearly 52 items via this command:
dir c:\temp\ | Measure-Object

The function only sees the last record of those 52. How do I access all 52 within my custom list-items function?

Body:
You need a process block that runs once for each item piped.

function hi {
  param([Parameter(ValueFromPipeline=$True)]$inputvalue)

  process {
    $inputvalue.count
  }

}

1,2,3 | hi

1
1
1


答:
The code you provided is very complicated to follow. You should try to use less for loops - it makes the code harder to read, and takes longer to execute (if you were performing something of larger scale). Take a look at my solution below, it prints the result as you would expect and is much easier to read and understand.

Here is the refactored code (note, since you didn't provide the course_roll function, I changed course_roll(records) for the variable course_rolls_records, so I could run it locally.):

```<code>def parse_course_code(commands):
    if commands in course_rolls_records.keys():
        print('Clashes with {}:'.format(commands))
        return clashes(commands)
    else:
        print("Unknown course code")

def clashes(course_code):
    numbers_in_course = course_rolls_records[course_code]
    collisions = {}
    for course_check in course_rolls_records.keys():
        numbers_in_course_check = course_rolls_records[course_check]
        if course_check == course_code:
            # This is the course we are querying, we don't need to do anything
            pass
        elif numbers_in_course_check.intersection(numbers_in_course):
            # We enter here if there are common student numbers between courses
            # Note: if there is no intersection, bool of empty set is False
            collisions[course_check] = list(numbers_in_course_check.intersection(numbers_in_course))
            print("In {} and {}  ".format(course_code, course_check))
            for num in collisions[course_check]:
                print("  {}: ".format(num))
            print('\n')

def main():
    while True:
        command = input('Command: ')
        if command == 'quit':
            print('Adios')
            break
        else:
            parse_course_code(command)

main()
</code>```

Title: How do I print the dict to the correct format?

Body:
I previously used course_rolls(records) to make the data to a dictionary below:

{'EMT001': {2286560}, 'FMKT01': {2547053}, 'CSC001': {2955520, 2656583}, 'MGM001': {2928707, 2606735}, 'MTH002': {2786372}, 'FCOM03': {2762453, 2955520, 2564885, 2606735}, 'FMCM02': {2955520, 2928707, 2656583}, 'ENG001': {2571096, 2564885}, 'MKT001': {2571096, 2656583},'AWA001': {2286560}, 'ACC002': {2762453}, 'FMTH01': {2571096}, 'EMT003': {2762453, 2656583}, 'MEA001': {2564885, 2606735}, 'FPHY01': {2564885}, 'FBIO01': {2547053}, 'MTH001': {2286560}, 'ECO002': {2928707, 2786372}, 'FCHM01': {2286560}, 'FCOM01': {2786372}, 'ENG002': {2762453}}

Records variable contains:

[(('EMT001', 'Engineering Mathematics 1'), (2286560, 'Dayton', 'Archambault')), (('FMKT01', 'Marketing'), (2547053, 'Vladimir', 'Zemanek')), (('CSC001', 'Computer Programming'), (2656583, 'Ronny', 'Ridley')), (('MGM001', 'Fundamentals of Management'), (2928707, 'Susanne', 'Eastland')), (('MTH002', 'Mathematics 2'), (2786372, 'Danella', 'Crabe')), (('FCOM03', 'Introduction to Computing'), (2564885, 'Hpone', 'Ganadry')), (('FCOM03', 'Introduction to Computing'), (2762453, 'Phelia', 'Pottle')), (('FMCM02', 'Mass Communication II (Film Studies)'), (2656583, 'Ronny', 'Ridley')), (('ENG001', 'Foundations of Engineering'), (2564885, 'Hpone', 'Ganadry')), (('MKT001', 'Principles of Marketing'), (2571096, 'Shoshanna', 'Shupe')), (('AWA001', 'Engineering Writing Skills'), (2286560, 'Dayton', 'Archambault')), (('FCOM03', 'Introduction to Computing'), (2606735, 'Aaren', 'Enns')), (('ACC002', 'Financial Accounting'), (2762453, 'Phelia', 'Pottle')), (('FMTH01', 'Advanced Mathematics I'), (2571096, 'Shoshanna', 'Shupe')), (('FCOM03', 'Introduction to Computing'), (2955520, 'Bjorn', 'Kakou')), (('EMT003', 'Mathematical Modelling and Computation'), (2762453, 'Phelia', 'Pottle')), (('MEA001', 'Mixed English Programme'), (2564885, 'Hpone', 'Ganadry')), (('MGM001', 'Fundamentals of Management'), (2606735, 'Aaren', 'Enns')), (('MEA001', 'Mixed English Programme'), (2606735, 'Aaren', 'Enns')), (('FPHY01', 'Physics'), (2564885, 'Hpone', 'Ganadry')), (('FBIO01', 'Introduction to Biology'), (2547053, 'Vladimir', 'Zemanek')), (('ENG001', 'Foundations of Engineering'), (2571096, 'Shoshanna', 'Shupe')), (('MKT001', 'Principles of Marketing'), (2656583, 'Ronny', 'Ridley')), (('MTH001', 'Mathematics 1'), (2286560, 'Dayton', 'Archambault')), (('ECO002', 'Introduction to Macroeconomics'), (2786372, 'Danella', 'Crabe')), (('FCHM01', 'Chemistry'), (2286560, 'Dayton', 'Archambault')), (('FCOM01', 'Communication Skills II'), (2786372, 'Danella', 'Crabe')), (('FMCM02', 'Mass Communication II (Film Studies)'), (2928707, 'Susanne', 'Eastland')), (('CSC001', 'Computer Programming'), (2955520, 'Bjorn', 'Kakou')), (('ENG002', 'Engineering Mechanics and Materials'), (2762453, 'Phelia', 'Pottle')), (('EMT003', 'Mathematical Modelling and Computation'), (2656583, 'Ronny', 'Ridley')), (('FMCM02', 'Mass Communication II (Film Studies)'), (2955520, 'Bjorn', 'Kakou')), (('ECO002', 'Introduction to Macroeconomics'), (2928707, 'Susanne', 'Eastland'))]

The program input is: clashes CSC001

Expected output (Command: clashes CSC001):

Clashes with CSC001:
In CSC001 and EMT003
  2656583:

In CSC001 and FCOM03
  2955520:

In CSC001 and FMCM02
  2656583:
  2955520:

In CSC001 and MKT001
  2656583:

The result I get (Command: clashes CSC001):

Clashes with CSC001:
In CSC001 and FCOM03
  2955520:

In CSC001 and FMCM02
  2955520:

In CSC001 and EMT003
  2656583:

In CSC001 and FMCM02
  2656583:

In CSC001 and MKT001
  2656583:

Program code: (clashes function need to fix)

def parse_course_code(commands, records):
    if commands in course_rolls(records).keys():
        print('Clashes with {}:'.format(commands))
        return clashes(commands, records)
    else:
        print("Unknown course code")

def clashes(course_code, records):
    unformatted_course_rolls = course_rolls(records)
    for course, prior_student_number in sorted(unformatted_course_rolls.items()):
        for prior_student_number_single in list(prior_student_number):
            if course_code == course:
                for code, student_number in sorted(unformatted_course_rolls.items()):
                    for num in list(student_number):
                        if prior_student_number_single == num and course != code:
                            print("In {} and {}  ".format(course, code))
                            print("  {}: \n".format(num))

def main():
    while True:
        command = input('Command: ')
        if command == 'quit':
            print('Adios')
            break
        else:
            parse_course_code(commands, records)
main()

Body:
The code you provided is very complicated to follow. You should try to use less for loops - it makes the code harder to read, and takes longer to execute (if you were performing something of larger scale). Take a look at my solution below, it prints the result as you would expect and is much easier to read and understand.

Here is the refactored code (note, since you didn't provide the course_roll function, I changed course_roll(records) for the variable course_rolls_records, so I could run it locally.):

def parse_course_code(commands):
    if commands in course_rolls_records.keys():
        print('Clashes with {}:'.format(commands))
        return clashes(commands)
    else:
        print("Unknown course code")

def clashes(course_code):
    numbers_in_course = course_rolls_records[course_code]
    collisions = {}
    for course_check in course_rolls_records.keys():
        numbers_in_course_check = course_rolls_records[course_check]
        if course_check == course_code:
            # This is the course we are querying, we don't need to do anything
            pass
        elif numbers_in_course_check.intersection(numbers_in_course):
            # We enter here if there are common student numbers between courses
            # Note: if there is no intersection, bool of empty set is False
            collisions[course_check] = list(numbers_in_course_check.intersection(numbers_in_course))
            print("In {} and {}  ".format(course_code, course_check))
            for num in collisions[course_check]:
                print("  {}: ".format(num))
            print('\n')

def main():
    while True:
        command = input('Command: ')
        if command == 'quit':
            print('Adios')
            break
        else:
            parse_course_code(command)

main()


问:
How to turn collapse on and off with javascript
I search with Laravel from the search box, and when I find it, I type bold and make the background color yellow. If the word I found is in collapse, can I make collapse open? I think I can do it with js. but how?
If there is a word in the search part, css changes like this.

```<code>$row->textMessage = preg_replace('/(' . $search . ')/i', "<b style='background-color: yellow'>$1</b>",
</code>```

The collapse I want to open is the message section here.

```<code><div id="{{'collapse'.$oMessage->id}}" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
                                            <div class="card-body">
                                                    <p><br>{!! $oMessage->htmlMessage !!}</p>
                                                    <p><br>{!! $oMessage->textMessage !!}</p>
                                            </div>
</code>```

答:
```<code>var a = $('b.highlighted-text').parents('div.collapse');
$(a).toggleClass('collapse collapse show')
</code>```

It takes the value of class and makes a collapse show. It was very simple 2 lines.

Body:
I search with Laravel from the search box, and when I find it, I type bold and make the background color yellow. If the word I found is in collapse, can I make collapse open? I think I can do it with js. but how?
If there is a word in the search part, css changes like this.

$row->textMessage = preg_replace('/(' . $search . ')/i', "$1",

The collapse I want to open is the message section here.

id}}" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">

{!! $oMessage->htmlMessage !!}

{!! $oMessage->textMessage !!}

Body:
var a = $('b.highlighted-text').parents('div.collapse');
$(a).toggleClass('collapse collapse show')

It takes the value of class and makes a collapse show. It was very simple 2 lines.


问:
Process.Start(url) in a loop not launching every instance
I have a need to launch multiple browser instances / tabs in succession but using Process.Start(url) I am finding that not every URL is launched.

```<code>    for (int i = 0; i < n; i++)
    {
        var p = Process.Start("http://localhost/#" + i.ToString());
    }
</code>```

For any value n > 1 I find that only the last URL is opened in the browser (I'm testing with IE as the default browser). If I add a Thread.Sleep(1000) after Process.Start then I see a variety of behavior: sometimes all n are created; sometimes a subset.

The following does work as expected, but assumes IE (would rather use the default browser) and launches n browser instances rather than n tabs:

```<code>    for (int i = 0; i < n; i++)
    {
        var p = Process.Start("iexplore.exe", "http://localhost/#" + i.ToString());
    }
</code>```

I would prefer to get it working with the default browser behavior, but need it to be deterministic.

答:
Ended up with the following, still not ideal (launches multiple browser windows), incorporating the command-line arg parsing solution Split string containing command-line parameters into string[] in C#

```<code>const int n = 3;
static void Main(string[] args)
{
    for (int i = 0; i < n; i++)
    {
        var start = GetDefaultBrowserStartInfo("http");
        start.Arguments += string.Format(" http://localhost/#{0}", i);

        var p = Process.Start(start);
    }
}

static ProcessStartInfo GetDefaultBrowserStartInfo(string scheme)
{
    string command = null;
    using (var key = Registry.ClassesRoot.OpenSubKey(string.Format(@"{0}\shell\open\command", scheme)))
    {
        command = (string)key.GetValue("");
    }

    string[] parsed = CommandLineToArgs(command);
    return new ProcessStartInfo
    {
        FileName = parsed[0],
        Arguments = string.Join(" ", parsed.Skip(1).ToArray()),
    };
}

[DllImport("shell32.dll", SetLastError = true)]
static extern IntPtr CommandLineToArgvW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);

static string[] CommandLineToArgs(string commandLine)
{
    int argc;
    var argv = CommandLineToArgvW(commandLine, out argc);
    if (argv == IntPtr.Zero)
        throw new System.ComponentModel.Win32Exception();
    try
    {
        var args = new string[argc];
        for (var i = 0; i < args.Length; i++)
        {
            var p = Marshal.ReadIntPtr(argv, i * IntPtr.Size);
            args[i] = Marshal.PtrToStringUni(p);
        }

        return args;
    }
    finally
    {
        Marshal.FreeHGlobal(argv);
    }
}
</code>```

}

Body:
I have a need to launch multiple browser instances / tabs in succession but using Process.Start(url) I am finding that not every URL is launched.

    for (int i = 0; i < n; i++)
    {
        var p = Process.Start("http://localhost/#" + i.ToString());
    }

For any value n > 1 I find that only the last URL is opened in the browser (I'm testing with IE as the default browser). If I add a Thread.Sleep(1000) after Process.Start then I see a variety of behavior: sometimes all n are created; sometimes a subset.

The following does work as expected, but assumes IE (would rather use the default browser) and launches n browser instances rather than n tabs:

    for (int i = 0; i < n; i++)
    {
        var p = Process.Start("iexplore.exe", "http://localhost/#" + i.ToString());
    }

I would prefer to get it working with the default browser behavior, but need it to be deterministic.

Body:
Ended up with the following, still not ideal (launches multiple browser windows), incorporating the command-line arg parsing solution Split string containing command-line parameters into string[] in C#

const int n = 3;
static void Main(string[] args)
{
    for (int i = 0; i < n; i++)
    {
        var start = GetDefaultBrowserStartInfo("http");
        start.Arguments += string.Format(" http://localhost/#{0}", i);

        var p = Process.Start(start);
    }
}

static ProcessStartInfo GetDefaultBrowserStartInfo(string scheme)
{
    string command = null;
    using (var key = Registry.ClassesRoot.OpenSubKey(string.Format(@"{0}\shell\open\command", scheme)))
    {
        command = (string)key.GetValue("");
    }

    string[] parsed = CommandLineToArgs(command);
    return new ProcessStartInfo
    {
        FileName = parsed[0],
        Arguments = string.Join(" ", parsed.Skip(1).ToArray()),
    };
}

[DllImport("shell32.dll", SetLastError = true)]
static extern IntPtr CommandLineToArgvW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);

static string[] CommandLineToArgs(string commandLine)
{
    int argc;
    var argv = CommandLineToArgvW(commandLine, out argc);
    if (argv == IntPtr.Zero)
        throw new System.ComponentModel.Win32Exception();
    try
    {
        var args = new string[argc];
        for (var i = 0; i < args.Length; i++)
        {
            var p = Marshal.ReadIntPtr(argv, i * IntPtr.Size);
            args[i] = Marshal.PtrToStringUni(p);
        }

        return args;
    }
    finally
    {
        Marshal.FreeHGlobal(argv);
    }
}

}


问:
Called read on non-open pipe
I was performing some osquery and i got the the exception

Code

import osquery

inst = osquery.SpawnInstance("C:\\ProgramData\\osquery\\osqueryi.exe")
inst.open()

cursor = inst.client

cursor.query("select name, version from programs;")
```

<h2>Complete Exeception</h2>

<pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
  File "app.py", line 8, in <module>
    cursor.query("select name, version from programs;")
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\extensions\ExtensionManager.py", line 181, in query
    self.send_query(sql)
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\extensions\ExtensionManager.py", line 190, in send_query
    self._oprot.trans.flush()
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\thrift\transport\TTransport.py", line 177, in flush
    self.__trans.write(out)
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\TPipe.py", line 128, in write
    message='Called read on non-open pipe')
thrift.transport.TTransport.TTransportException: Called read on non-open pipe
</code>```

答: The error got resolved after installing Apache thrift and its python module</p>

Title: Called read on non-open pipe

Body:
I was performing some osquery and i got the the exception

Code

import osquery

inst = osquery.SpawnInstance("C:\\ProgramData\\osquery\\osqueryi.exe")
inst.open()

cursor = inst.client

cursor.query("select name, version from programs;")

Complete Exeception

Traceback (most recent call last):
  File "app.py", line 8, in <module>
    cursor.query("select name, version from programs;")
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\extensions\ExtensionManager.py", line 181, in query
    self.send_query(sql)
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\extensions\ExtensionManager.py", line 190, in send_query
    self._oprot.trans.flush()
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\thrift\transport\TTransport.py", line 177, in flush
    self.__trans.write(out)
  File "C:\Users\malware-test\Anaconda3\lib\site-packages\osquery\TPipe.py", line 128, in write
    message='Called read on non-open pipe')
thrift.transport.TTransport.TTransportException: Called read on non-open pipe


问:
InputMismatchError while scanning number
While trying to read a number using below code InputMismatchError is generated:

```<code>Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {

    long number = sc.nextLong(); // Error here

    if (number % 2 == 0 && number != 0) {
        System.out.println("even");
    } else if (number % 2 != 0 && number != 0) {
        System.out.println("odd");
    } else if (number == 0) {
        System.out.println("");
    }
}
</code>```

I don't understand where a mistake. Eclipse compiled program without errors.

Following is the input from console used

1234.5

答:
You could do this way

```<code>Scanner scan = new Scanner(System.in);
long val = scan.nextLong();
System.out.printf(String.valueOf(val));
</code>```

while you are expecting long you should pass non-decimal numeric value from command line.

Body:
While trying to read a number using below code InputMismatchError is generated:

Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {

    long number = sc.nextLong(); // Error here

    if (number % 2 == 0 && number != 0) {
        System.out.println("even");
    } else if (number % 2 != 0 && number != 0) {
        System.out.println("odd");
    } else if (number == 0) {
        System.out.println("");
    }
}

I don't understand where a mistake. Eclipse compiled program without errors.

Following is the input from console used

1234.5

Body:
You could do this way

Scanner scan = new Scanner(System.in);
long val = scan.nextLong();
System.out.printf(String.valueOf(val));

while you are expecting long you should pass non-decimal numeric value from command line.