问:
How do i use nth-child to the icons while hovering?
How do I use nth-child technique so that each time use hover a particular icon, it should change color and pop-up without disturbing the others. I tried and the effects are working for every icons not on a particular one.

.icon ul li {
  list-style: none;
  display: inline;
  margin: 30px;
}

.icon {
  background: #000;
}

.icon ul li a {
  text-decoration: none;
  color: crimson;
  padding: 10px;
}

.icon ul li a i {
  font-size: 20px;
}

.icon ul li a:nth-child(1):hover {
  color: blue;
  font-size: 25px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth"
rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">

<label><strong>Or follow Us -</strong></label>
<div class="icon">
  <ul>
    <li><i class="fa fa-facebook"></i></li>
    <li><i class="fa fa-twitter"></i></li>
    <li><i class="fa fa-linkedin"></i></li>
    <li><i class="fa fa-youtube"></i></li>
    <li><i class="fa fa-instagram"></i></li>
  </ul>
</div></code>```

答:
.icon ul li {
  list-style: none;
  display: inline;
  margin: 30px;
}
.icon {
  background: #000;
}
.icon ul li a {
  text-decoration: none;
  color: crimson;
  padding: 10px;
}
.icon ul li a {
  font-size: 25px;
}
.icon ul li:nth-child(1) a:hover {
  color: blue;
}
.icon ul li:nth-child(2) a:hover {
  color: yellow;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth"
rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">
</head>
<body>
<label><strong>Or follow Us -</strong></label>
<div class="icon">
  <ul>
    <li><i class="fa fa-facebook"></i></li>
    <li><i class="fa fa-twitter"></i></li>
    <li><i class="fa fa-linkedin"></i></li>
    <li><i class="fa fa-youtube"></i></li>
    <li><i class="fa fa-instagram"></i></li>
  </ul>
</div></code>```

Body:
How do I use nth-child technique so that each time use hover a particular icon, it should change color and pop-up without disturbing the others. I tried and the effects are working for every icons not on a particular one.

.icon ul li {
  list-style: none;
  display: inline;
  margin: 30px;
}

.icon {
  background: #000;
}

.icon ul li a {
  text-decoration: none;
  color: crimson;
  padding: 10px;
}

.icon ul li a i {
  font-size: 20px;
}

.icon ul li a:nth-child(1):hover {
  color: blue;
  font-size: 25px;
}

<link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth"
rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">

Or follow Us -

Body:
.icon ul li {
  list-style: none;
  display: inline;
  margin: 30px;
}
.icon {
  background: #000;
}
.icon ul li a {
  text-decoration: none;
  color: crimson;
  padding: 10px;
}
.icon ul li a {
  font-size: 25px;
}
.icon ul li:nth-child(1) a:hover {
  color: blue;
}
.icon ul li:nth-child(2) a:hover {
  color: yellow;
}

<link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth"
rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">
</head>
<body>
<label><strong>Or follow Us -</strong></label>
<div class="icon">
  <ul>
    <li><a href="https://facebook.com"><i class="fa fa-facebook"></i></a></li>
    <li><a href="https://twitter.com"><i class="fa fa-twitter"></i></a></li>
    <li><a href="https://linkedin.com"><i class="fa fa-linkedin"></i></a></li>
    <li><a href="https://Youtube.com"><i class="fa fa-youtube"></i></a></li>
    <li><a href="https://instagram.com"><i class="fa fa-instagram"></i></a></li>
  </ul>
</div>


来源: stackexchange

问:
How to get JSON Data sent through postman tool using post method?
I'm trying to get a JSON data which is sent as JSON data using postman tool and trying to receive it my post() method.

```<code>    var express = require('express');
    var app = express();

    app.post('/myData',function(req,res){
        console.log("--->",req.body);
    });

var server = app.listen(8080,function(){});
</code>```

This is the JSON data sent through postman tool

I'm getting undefined in my console as
"---> undefined"

I'm trying to retrieve the JSON data set in my postman tool to either my console or browser

答:
Add res.send(req.body); inside the app.post method.

```<code>    app.post('/myData',function(req,res){
        console.log("--->",req.body);
        res.send(req.body);
    });
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to get a JSON data which is sent as JSON data using postman tool and trying to receive it my post() method.

    var express = require('express');
    var app = express();

    app.post('/myData',function(req,res){
        console.log("--->",req.body);
    });

var server = app.listen(8080,function(){});

This is the JSON data sent through postman tool

I'm getting undefined in my console as
"---> undefined"

I'm trying to retrieve the JSON data set in my postman tool to either my console or browser

Body:
Add res.send(req.body); inside the app.post method.

    app.post('/myData',function(req,res){
        console.log("--->",req.body);
        res.send(req.body);
    });


问:
How do I add a class to WTForm Radio field?
I am attempting to style my WTForm Radio inputs with UIkit, but when looping through each field, I can't figure out how to get the class to apply. If I add the form.difficulty(class_"uk-radio") to the for loop, I get a crazy output instead of the formatted field. What is the proper syntax to apply this UIkit class to the radio field within a WTForm?

Thanks!

HTML:

```<code>{% from "_formhelpers.html" import render_field %}
<form class="uk-grid-small uk-background-muted uk-padding" action="/ask/" method="post" uk-grid>
    <div class="uk-width-1-2@s uk-margin-small">{{ render_field(form.title,placeholder="The Problem", class_="uk-input") }}</div><br>

    <div class="uk-width-1-1 uk-margin-small">
        <strong>Question Difficulty:</strong>
        <br>
        {% for subfield in form.difficulty(class_="uk-radio") %}
            <tr>
                <td>{{ subfield.label }}</td>
                <td>{{ subfield }}</td>

            </tr>
        {% endfor %}
    </div>
    <br>

    <div class="uk-width-1-1 uk-margin-small">
        {{ render_field(form.body,placeholder="My device probably has a virus. I clicked the wrong link, and I have like a million popups a minute now. Minute.tech HELP! I need some direction here guys.", class_="uk-textarea", rows="20", cols="100") }}
    </div>
    <br>
    <div class="uk-width-1-1 uk-margin-small">{{ render_field(form.tags,placeholder="Mac, virus, Facebook, etc", class_="uk-input") }}</div>
    <br>
    <div class="uk-width-1-4@s uk-margin-small">
        <input class="uk-button uk-button-primary" type="submit" value="Ask">
    </div>
</form>
</code>```

Python

```<code>class AskForm(Form):
    difficulty = RadioField('Difficulty Rating', choices = [('1','1'), ('2','2'),('3','3'),('4','4'),('5','5')])
    title = TextField('Title:', [validators.Length(min=5, max=100)])
    body = TextAreaField('Desciption:', [validators.Length(min=10, max=2000)])
    tags = TextField('Tags:', [validators.Optional()])
</code>```

Results:

EDIT:
Tried {{ render_field(form.difficulty, class_="uk-input") }}, output still formatted vertically and not styled

Result:

答:
There are no subfields, difficulty is one field with multiple choices.

Render it like any other field and it should work.

```<code>{{ render_field(form.difficulty, class_="uk-input") }}
</code>```

Body:
I am attempting to style my WTForm Radio inputs with UIkit, but when looping through each field, I can't figure out how to get the class to apply. If I add the form.difficulty(class_"uk-radio") to the for loop, I get a crazy output instead of the formatted field. What is the proper syntax to apply this UIkit class to the radio field within a WTForm?

Thanks!

HTML:

{% from "_formhelpers.html" import render_field %}
<form class="uk-grid-small uk-background-muted uk-padding" action="/ask/" method="post" uk-grid>

{{ render_field(form.title,placeholder="The Problem", class_="uk-input") }}

        Question Difficulty:

        {% for subfield in form.difficulty(class_="uk-radio") %}

                {{ subfield.label }}
                {{ subfield }}

        {% endfor %}

        {{ render_field(form.body,placeholder="My device probably has a virus. I clicked the wrong link, and I have like a million popups a minute now. Minute.tech HELP! I need some direction here guys.", class_="uk-textarea", rows="20", cols="100") }}

{{ render_field(form.tags,placeholder="Mac, virus, Facebook, etc", class_="uk-input") }}

        <input class="uk-button uk-button-primary" type="submit" value="Ask">

</form>

Python

class AskForm(Form):
    difficulty = RadioField('Difficulty Rating', choices = [('1','1'), ('2','2'),('3','3'),('4','4'),('5','5')])
    title = TextField('Title:', [validators.Length(min=5, max=100)])
    body = TextAreaField('Desciption:', [validators.Length(min=10, max=2000)])
    tags = TextField('Tags:', [validators.Optional()])

Results:

EDIT:
Tried {{ render_field(form.difficulty, class_="uk-input") }}, output still formatted vertically and not styled

Result:

Body:
There are no subfields, difficulty is one field with multiple choices.

Render it like any other field and it should work.

{{ render_field(form.difficulty, class_="uk-input") }}


问:
Kill a stuck thread on a running VM (JBoss Instance) in Java?
A bug in a third party library is causing an infinite loop in a worker thread on a JBoss instance of mine.  Do you know of a way to kill this "stuck" thread without restarting the server?  We'd like to be able to recover from this  until a fix is deployed, preferably without having to restart.

I've seen a few people mention using Thread.interrupt() - if I were to code my own MBean, how would I get a handle to the thread in question in order to interrupt it?

Update: Wasn't able to solve using any of these methods.  I did come across another thread about the same issue that had a link to why Thread.stop() is deprecated. Someone else has asked a similar question with similar results. It seems like more sophisticated containers should provide this kind of health mechanism, but I guess their hands are tied w/r/t the JVM.

答:
I had a similar bug (infinite loop) in a 3rd party lib.  I ended up applying the fix myself (while waiting for the people from the 3rd party lib to fix their mess) and then I placed the modified .class in my .war, making sure it is loaded before the bogus .class (the bogus one being inside the bogus 3rd party .jar).

It is not nice but it works, see my question here:

Order of class loading from a .war file

What I mean is this: if you have to wait for the people responsible for the 3rd party bugged lib to fix their stuff, you can potentially be waiting a very long time.  We couldn't afford that.  We needed a fix ASAP.  So we ended up applying a patch/hack to their code.

You could for example add a boolean check inside the infinite loop and then forcing the loop to exit when you want the bogus thread to "die".

Note that I haven't used the deprecated Thread stop() since ten years and I really didn't want to use it in the above case.

ContentLicense: CC BY-SA 2.5


问:
How to run a shell command at analysis time in bazel?
I'm trying to bake the mercurial version into my Bazel file, so that I can get something like this:

```<code># These I set manually, since they're "semantic"
MAJOR_VERSION = 2
MINOR_VERSION = 3
BUGFIX_VERSION = 1

# This should be the result of `hg id -n`
BUILD_VERSION = ?

apple_bundle_version(
    name = "my_version",
    build_version = "{}.{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION, BUILD_VERSION),
    short_version_string = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION),
)
</code>```

This obviously is not hermetic, so I know it violates some of Bazel's assumptions, so I'm open to other options.

Here's some possible options:

Actually run hg id -n during Bazel analysis, which I don't know how to do.

Pass the build version in via command line, e.g., --define=build_version=$(hg id -n). Unfortunately, this requires a separate command to wrap bazel build.

Manually set the BUILD_VERSION. Obviously, this would be annoying.

Is there a way to do #1? What are my other options?

答:
Yes, you can do this with a custom --workspace_status_command and a genrule that processes the information and generates source files with this data.

EDIT: I removed the parts about the --stamp flag, it's not needed.

Summary

Build with --workspace_status_command=/path/to/binary with a custom binary or shell script that runs hg and outputs the information you need.

Write a genrule with stamp=1.

Details

1. --workspace_status_command=/path/to/binary

The --workspace_status_command=<path> flag lets you specify a binary.

Bazel runs this binary before each build. The binary should write key-value pairs to stdout. Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and "volatile" are a bit counter-intuitive, so don't think much about them.)

Bazel then writes the key-value pairs into two files:

bazel-out/stable-status.txt contains all keys and values where the key's name starts with STABLE_

bazel-out/volatile-status.txt contains the rest of the keys and their values

The contract is:

"stable" keys' values should change rarely, if possible. If the contents of stable-status.txt change, it invalidates the actions that depend on them, e.g. the genrule.cmd if that genrule has stamp=1. In other words, if a stable key's value changes, it'll make Bazel rebuild stamped actions. Therefore the stable status should not contain things like timestamps, because they change all the time, and would make Bazel rebuild the stamped actions with each build.

"volatile" keys' values may change often. Bazel expects them to change all the time, like timestamps do, and duly updates the volatile-status.txt file. In order to avoid rebuilding stamped actions all the time though, Bazel pretends that the volatile file never changes. In other words, if the volatile status file is the only one whose contents changed, that will not invalidate actions that depend on it. If other inputs of the actions have changed, then Bazel rebuilds that action, and the action may then use the updated volatile status. But just the volatile status changing alone will not invalidate the action.

Example for my-status.sh:

```<code>#!/bin/bash
echo STABLE_GIT_BRANCH $(git rev-parse HEAD)
echo MY_TIMESTAMP $(date)
</code>```

2. Write a genrule with stamp=1.

This attribute is undocumented, which surprises me. I'll file a bug about that.

Example for foo/BUILD:

```<code>genrule(
    name = "x",
    srcs = ["input.txt"],
    outs = ["x.txt"],
    cmd = " ; ".join([
        "( echo 'volatile data:'",
        "cat bazel-out/volatile-status.txt",
        "echo ---",
        "echo 'stable data:'",
        "cat bazel-out/stable-status.txt",
        ") > $@",
    ]),
    stamp = 1,
)
</code>```

Putting it all together

The genrule isn't rebuilt

...when only bazel-out/volatile-status.txt changes:

```<code>  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379211456
MY_TIMESTAMP Mon Dec 4 10:20:11 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ cat bazel-out/volatile-status.txt
BUILD_TIMESTAMP 1512379425898
MY_TIMESTAMP Mon Dec 4 10:23:45 CET 2017

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379211456
MY_TIMESTAMP Mon Dec 4 10:20:11 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ cat bazel-out/volatile-status.txt
BUILD_TIMESTAMP 1512379441919
MY_TIMESTAMP Mon Dec 4 10:24:01 CET 2017
</code>```

The genrule is rebuilt

...when the stable status or the genrule's inputs change:

```<code>  $ echo bar > foo/input.txt

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379566646
MY_TIMESTAMP Mon Dec 4 10:26:06 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ git checkout HEAD~1 &>/dev/null

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379594890
MY_TIMESTAMP Mon Dec 4 10:26:34 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH b3da717469e23f5293297175a80709956416fd2c
</code>```

Body:
I'm trying to bake the mercurial version into my Bazel file, so that I can get something like this:

# These I set manually, since they're "semantic"
MAJOR_VERSION = 2
MINOR_VERSION = 3
BUGFIX_VERSION = 1

# This should be the result of `hg id -n`
BUILD_VERSION = ?

apple_bundle_version(
    name = "my_version",
    build_version = "{}.{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION, BUILD_VERSION),
    short_version_string = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION),
)

This obviously is not hermetic, so I know it violates some of Bazel's assumptions, so I'm open to other options.

Here's some possible options:

Actually run hg id -n during Bazel analysis, which I don't know how to do.

Pass the build version in via command line, e.g., --define=build_version=$(hg id -n). Unfortunately, this requires a separate command to wrap bazel build.

Manually set the BUILD_VERSION. Obviously, this would be annoying.

Is there a way to do #1? What are my other options?

Body:
Yes, you can do this with a custom --workspace_status_command and a genrule that processes the information and generates source files with this data.

EDIT: I removed the parts about the --stamp flag, it's not needed.

Summary

Build with --workspace_status_command=/path/to/binary with a custom binary or shell script that runs hg and outputs the information you need.

Write a genrule with stamp=1.

Details

1. --workspace_status_command=/path/to/binary

The --workspace_status_command=<path> flag lets you specify a binary.

Bazel runs this binary before each build. The binary should write key-value pairs to stdout. Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and "volatile" are a bit counter-intuitive, so don't think much about them.)

Bazel then writes the key-value pairs into two files:

bazel-out/stable-status.txt contains all keys and values where the key's name starts with STABLE_

bazel-out/volatile-status.txt contains the rest of the keys and their values

The contract is:

"stable" keys' values should change rarely, if possible. If the contents of stable-status.txt change, it invalidates the actions that depend on them, e.g. the genrule.cmd if that genrule has stamp=1. In other words, if a stable key's value changes, it'll make Bazel rebuild stamped actions. Therefore the stable status should not contain things like timestamps, because they change all the time, and would make Bazel rebuild the stamped actions with each build.

"volatile" keys' values may change often. Bazel expects them to change all the time, like timestamps do, and duly updates the volatile-status.txt file. In order to avoid rebuilding stamped actions all the time though, Bazel pretends that the volatile file never changes. In other words, if the volatile status file is the only one whose contents changed, that will not invalidate actions that depend on it. If other inputs of the actions have changed, then Bazel rebuilds that action, and the action may then use the updated volatile status. But just the volatile status changing alone will not invalidate the action.

Example for my-status.sh:

#!/bin/bash
echo STABLE_GIT_BRANCH $(git rev-parse HEAD)
echo MY_TIMESTAMP $(date)

2. Write a genrule with stamp=1.

This attribute is undocumented, which surprises me. I'll file a bug about that.

Example for foo/BUILD:

genrule(
    name = "x",
    srcs = ["input.txt"],
    outs = ["x.txt"],
    cmd = " ; ".join([
        "( echo 'volatile data:'",
        "cat bazel-out/volatile-status.txt",
        "echo ---",
        "echo 'stable data:'",
        "cat bazel-out/stable-status.txt",
        ") > $@",
    ]),
    stamp = 1,
)

Putting it all together

The genrule isn't rebuilt

...when only bazel-out/volatile-status.txt changes:

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379211456
MY_TIMESTAMP Mon Dec 4 10:20:11 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ cat bazel-out/volatile-status.txt
BUILD_TIMESTAMP 1512379425898
MY_TIMESTAMP Mon Dec 4 10:23:45 CET 2017

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379211456
MY_TIMESTAMP Mon Dec 4 10:20:11 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ cat bazel-out/volatile-status.txt
BUILD_TIMESTAMP 1512379441919
MY_TIMESTAMP Mon Dec 4 10:24:01 CET 2017

The genrule is rebuilt

...when the stable status or the genrule's inputs change:

  $ echo bar > foo/input.txt

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379566646
MY_TIMESTAMP Mon Dec 4 10:26:06 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH d3fed125d00f6f61bfbfe05f4566656cdac1ea6e

  $ git checkout HEAD~1 &>/dev/null

  $ bazel build --workspace_status_command=/tmp/foo/ws.sh //foo:x &>/dev/null && cat bazel-genfiles/foo/x.txt
volatile data:
BUILD_TIMESTAMP 1512379594890
MY_TIMESTAMP Mon Dec 4 10:26:34 CET 2017
---
stable data:
BUILD_EMBED_LABEL
BUILD_HOST <redacted>
BUILD_USER <redacted>
STABLE_GIT_BRANCH b3da717469e23f5293297175a80709956416fd2c


问:
Haskell :: Parsing Line of Text into a List of List

Hi guys,

I'm parsing a text file which look like this:

```<code>114.474998474121 15.7440004348755 25.806999206543 -873 172 182 188
114.46199798584 15.7419996261597 25.8799991607666 -1396 180 192 205
</code>```

And wish it can read as like this:

```<code>[[114.475,15.744,25.807,-873.0,172.0,182.0,188.0],
[114.462,15.742,25.88,-1396.0,180.0,192.0,205.0]]
</code>```

Currently my code for this text parsing doesn't give that. Here is my code:

```<code>main = do
    text <- readFile "mytext.txt"
    let
        pcVal = map read (words text) :: [Float]
    print pcVal
    return ()
</code>```

This code parsed all the text as a single list like this:

```<code>[114.475,15.744,25.807,-873.0,172.0,182.0,188.0,
114.462,15.742,25.88,-1396.0,180.0,192.0,205.0]
</code>```

I couldn't find how to take the whole single line (in text file) as a list, and the second line as another list till end of the file. Appreciate if somebody have experience in this. Thanks.

答:
You can use the lines function; for example map words $ lines text.

This would also be a good time for a helper function, ie

```<code>let parse :: String -> [Float]
    parse line = map read $ words line
    pcVal = map parse $ lines text
</code>```

Body:
Hi guys,

I'm parsing a text file which look like this:

114.474998474121 15.7440004348755 25.806999206543 -873 172 182 188
114.46199798584 15.7419996261597 25.8799991607666 -1396 180 192 205

And wish it can read as like this:

[[114.475,15.744,25.807,-873.0,172.0,182.0,188.0],
[114.462,15.742,25.88,-1396.0,180.0,192.0,205.0]]

Currently my code for this text parsing doesn't give that. Here is my code:

main = do
    text <- readFile "mytext.txt"
    let
        pcVal = map read (words text) :: [Float]
    print pcVal
    return ()

This code parsed all the text as a single list like this:

[114.475,15.744,25.807,-873.0,172.0,182.0,188.0,
114.462,15.742,25.88,-1396.0,180.0,192.0,205.0]

I couldn't find how to take the whole single line (in text file) as a list, and the second line as another list till end of the file. Appreciate if somebody have experience in this. Thanks.

Body:
You can use the lines function; for example map words $ lines text.

This would also be a good time for a helper function, ie

let parse :: String -> [Float]
    parse line = map read $ words line
    pcVal = map parse $ lines text


问:
Typescript validator not working in my angular IDE Eclipse Plugin
If i enter wrong code in typescript editor it doesn't show me any compile time error. I don't know why typescript validator doesn't work. I am using eclipse Neon.3 Release (4.6.3) with angular IDE plugin. Do i have to add anything further to support typescript validator please let me know.

答:
I'm not sure which errors are not being flagged for you but there is a setting in the project properties (TypeScript preference page) for enabling TSlint validation if tslint.json is present in the project. This is a per-project setting, not available for the workspace as a whole.

If this doesn't help, perhaps you could give an example of the type of error that is not being flagged? Or is it that the errors aren't being flagged but do appear in the Markers or Problems view? Try a fresh workspace and a new Angular project (or other project with Typescript files) just to check if this may be some corruption in your existing workspace settings.


问:
Can i store html content of webpage in storm crawler?
I am using strom-crawler-elastic. I can able to see the fetched urls and status of those. Configuration change in ES_IndexInit.sh file gives only url,title, host, text. But can i store the entire html content with html tags ?</p>

答:
The ES IndexerBolt gets the content of pages from the ParseFilter but does not do anything with it. One option would be to modify the code so that it pulls the content field from the incoming tuples and indexes it.

Alternatively, you could implement a custom ParseFilter which would copy the content of the page into a metadata key value and configure that field to be indexed via indexer.md.mapping in the configuration file.

Either way, you'd need to modify ES_indexInit.sh so that the field in ES gets indexed and/or stored the way you want it.

.


问:
fastest way to match fingerprints?
I am trying to check whether a fingerprint exists/matches in a huge collection of fingerprints (100,000 fingerprints). It will take more time to search for matches sequentially. is there any better way to search for match? is it possible to organize the fingerprints in a binary tree structure so that the number of comparisons can be reduced? if yes how can we do it? it would be helpful if the answers are in Java perspective.

edit:

I have all the fingerprints as .gif images. how can i convert the finger print images into data?

Thanks.

答:
You can't just do some kind of image comparison - there are specific ways to analyze and store fingerprint information already established which, for example, take into account the quality of the lifted/scanned fingerprint and that of the stored fingerprint data.

I googled for fingerprint encoding standard and came up with several interesting results, including the Encyclopedia of Biometrics which mentions "quality in various fingerprint encoding standards", and an article talking about the FBI image coding standard (among other things)

Title: fastest way to match fingerprints?


问:
My Django website not showing any forms when I edit
I'm building a website using Django.
And for somereason, the dictionary using all the forms is not showing at all..

When I click my Edit button the modal is showing without the forms...

forms.server_id needs to contain all the forms using server_id...
the server_id I use to show the previous data when I edit.

But for some reason, it doesn't show any form at all...

index.html -

```<code>{% load static i18n util_filters %}
<html lang="en">

<head>
        <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.2.1/jq-3.2.1/dt-1.10.16/af-2.2.2/b-1.4.2/fc-3.2.3/fh-3.1.3/kt-2.3.2/r-2.2.0/rg-1.0.2/rr-1.2.3/sc-1.4.3/sl-1.2.3/datatables.min.css"/>

        <script src="https://use.fontawesome.com/3c2c6890cf.js"></script>

        <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jq-3.2.1/jq-3.2.1/dt-1.10.16/af-2.2.2/b-1.4.2/fc-3.2.3/fh-3.1.3/kt-2.3.2/r-2.2.0/rg-1.0.2/rr-1.2.3/sc-1.4.3/sl-1.2.3/datatables.min.js"></script>

        <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="{% url 'serverlist' %}">DevOps Map</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">

          <li class="nav-item">
            <a class="nav-link" href="{% url 'serverlist' %}">Servers</a>
          </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'serverlist'  %}">Switches</a>
                </li>

        </ul>
      </div>
    </nav>

<style type="text/css">
.wrapper {
    display:flex;
}
</style>
</head>

<body>

<div class="container">

    <br>
    <center><h1 class="display-4">DevOps Server List</h1></center>
    <br>

    <center><button type="button" class="save btn btn-outline-success btn-lg" data-toggle="modal" data-target=".AddServer">Add Server <i class="fa fa-server fa-lg" aria-hidden="true"></i></button></center>
    <table class="table table-hover table-bordered table-condensed" cellspacing="0" width="1300" id="ServerTable">
    <thead>

      <tr>
        <th><center> #</center></th>
        <th><center>  Server Name </center></th></center>
        <th><center>  Owner </center></th></center>
        <th><center>  Project </center></th></center>
        <th><center>  Description </center></th></center>
        <th><center>  IP Address </center></th></center>
        <th><center> ILO </center></th></center>
        <th><center>  Rack </center></th></center>
        <th><center>  Status </center></th></center>
        <th><center>      Actions        </center></th></center>

        </tr>
        </thead>
    <tbody>

                {% for server in posts %}

        <tr>
          <div class ="server">
            <td></td>
            <td><center>{{ server.ServerName }}</center></td>
            <td><center>{{ server.Owner }}</center></td>
            <td><center>{{ server.Project }}</center></td>
            <td><center>{{ server.Description }}</center></td>
            <td><center>{{ server.IP }}</center></td>
            <td><center>{{ server.ILO }}</center></td>
            <td><center>{{ server.Rack }}</center></td>
            <td><h4><span class="badge badge-success">Online</span></h4></td></center>

            <td>

            <button type="button" class="btn btn-outline-danger" data-toggle="modal" href="#delete-server-{{server.id}}"
             data-target="#Del{{server.id}}">Delete <i class="fa fa-trash-o"></i></button>
            <button type="button" class="btn btn-outline-primary" data-toggle="modal" href="#edit-server-{{server.id}}"
             data-target="#Edit{{server.id}}">   Edit             <i class="fa fa-pencil"></i></button>

                        <div id ="Del{{server.id}}" class="modal fade" role="document">
                            <div class="modal-dialog" id="delete-server-{{server.id}}">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title">Delete Confirmation</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">×</span>
                                    </button>
                                        </div>
                                        <div class="modal-body">
                                        <form action="{% url 'delete_post' server.id %}" method="post">{% csrf_token %}
                                            <h6>Are you sure you want to delete {{ server.ServerName }}?</h6>
                                                <br>
                                            <center><input type="submit" class="btn btn-danger btn-md" value="Confirm"/>
                                                <button type="submit" class="btn btn-secondary" data-dismiss="modal">Cancel</button></center>

                                        </form>
                                    </div>
                                    </div>

                        </div>
            </div>

            <div class="modal fade bd-example-modal-sm" id="Edit{{server.id}}" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
                        <div class="modal-header">
                                <h5 class="modal-title">Edit Server <strong>{{ server.ServerName }}</strong> </h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                </button>
                        </div>
                                <div class="modal-body">

                                                                        {% with server.id as server_id %}
                                                                        {% with forms|get_by_key:server_id as edit_form %}
                                        <form action="{% url 'edit_post'  server_id %}" method="post"> {% csrf_token %}

                                <!--<center>    {{ edit_form.as_p }} </center> -->
                                        {% for field in forms.server_id %}

                                                            <div class="fieldWrapper">

                                                {{ field.errors }}
                                                                        <!-- {{ field.label_tag }} -->

                                <small><strong>{{ field.html_name }}<p align="left"></b> {{ field }}</small> </strong>

                                                {% if field.help_text %}
                                                <p class="help">{{ field.help_text|safe }}</p>
                                                {% endif %}

                                                        </div>

                                                {% endfor %}
                                                                </div>
                <div class="wrapper">

                <h2><button type="submit" class="save btn btn-success btn-lg">Confirm</button></h2>
                                <h2><button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal">Cancel</button></h2>
                </div>

                </form>
                {% endwith %}
                {% endwith %}

                </div>
                </td>
        </tr>
                {% endfor %}
    </tbody>
</h5>
    </table>

<div class="modal fade AddServer" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Add Server</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
                <div class="modal-body">
                    <form method="post" novalidate> {% csrf_token %}
                    <!--<center>    {{ form.as_p }} </center> -->
                            {% for field in form %}
                                <div class="fieldWrapper">
                            {{ field.errors }}
                                    <!-- {{ field.label_tag }} -->

                    <small><strong>{{ field.html_name }}</strong></small><p align="left"></b> {{ field }}   </p>

                            {% if field.help_text %}
                            <p class="help">{{ field.help_text|safe }}</p>
                            {% endif %}

                            </div>

                {% endfor %}

                </div>
                <div class="wrapper">

                <h2><button type="submit" class="save btn btn-success btn-lg" >Confirm</button></h2>
                <h2><button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal">Cancel</button></h2>
                </div>
            </div>
        </form>
    </div>
  </div>
</div>
</code>```

views.py -

```<code># Create your views here.

from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
from django.shortcuts import render, redirect
from django.template import RequestContext
from django.views.generic import TemplateView, UpdateView, DeleteView, CreateView
from DevOpsWeb.forms import HomeForm
from DevOpsWeb.models import serverlist
from django.core.urlresolvers import reverse_lazy
from simple_search import search_filter
from django.db.models import Q

class HomeView(TemplateView):

    template_name = 'serverlist.html'

    def get(self, request):

        form = HomeForm()
        query = request.GET.get("q")
        posts = serverlist.objects.all()

        forms = {}

        if query:
            posts = serverlist.objects.filter(Q(ServerName__icontains=query) | Q(Owner__icontains=query) | Q(Project__icontains=query) | Q(Description__icontains=query) | Q(IP__icontains=query) | Q(ILO__icontains=query) | Q(Rack__icontains=query))
        else:
            posts = serverlist.objects.all()
        #for post in posts:
        #    form = HomeForm(instance=post)
        for post in posts:
            forms[post.id] = HomeForm(instance=post)
        args = {'form' : form,'forms': forms, 'posts' : posts}
        #args = {'form' : form, 'forms': forms, 'posts' : posts}
        return render(request, self.template_name, args)

    def post(self,request):
        form = HomeForm(request.POST)
        posts = serverlist.objects.all()

        if form.is_valid(): # Checks if validation of the forms passed
            post = form.save(commit=False)
            post.save()
            #form = HomeForm()
            return redirect('serverlist')
        for post in posts:
            forms[post.id] = HomeForm(instance=post)
        args = {'form' : form, 'forms': forms, 'posts' : posts}
        #args = {'form' : form,'forms': forms, 'posts' : posts}
        return render(request, self.template_name,args)

class PostDelete(DeleteView):
    model = serverlist
    success_url = reverse_lazy('serverlist')

class PostEdit(UpdateView):
    template_name = 'serverlist.html'
    model = serverlist
    form_class = HomeForm
    #fields = ['ServerName','Owner','Project','Description','IP','ILO','Rack','Status']

    success_url = reverse_lazy('serverlist')
    #def get_object(self):
    #    obj = get_object_or_404(Calification, pk=self.request.POST.get('pk'))
    #    return obj
</code>```

答:
This :

```<code>{% with server.id as server_id %}
    {# ... #}
    {{ forms.server_id.as_p }}
</code>```

just cannot work - it will look for forms["server_id"] (=> use the literal string "server_id" as key). You will need a custom template filter, such as the one described here. And as Daniel Roseman rightly mentions in a comment, you'll have to pass whatever server is supposed to be to your template's context too.

Also note that you're going to get a NameError in HomeView.post - you copy-pasted part of the code filling in your posts dict but not the part instanciating it. You should really factor this out instead of copy-pasting.

Body:
I'm building a website using Django.
And for somereason, the dictionary using all the forms is not showing at all..

When I click my Edit button the modal is showing without the forms...

forms.server_id needs to contain all the forms using server_id...
the server_id I use to show the previous data when I edit.

But for some reason, it doesn't show any form at all...

index.html -

{% load static i18n util_filters %}

        <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.2.1/jq-3.2.1/dt-1.10.16/af-2.2.2/b-1.4.2/fc-3.2.3/fh-3.1.3/kt-2.3.2/r-2.2.0/rg-1.0.2/rr-1.2.3/sc-1.4.3/sl-1.2.3/datatables.min.css"/>

      DevOps Map
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">

      </button>

            Servers

                    Switches

DevOps Server List

    <button type="button" class="save btn btn-outline-success btn-lg" data-toggle="modal" data-target=".AddServer">Add Server </button>

         #
          Server Name
          Owner
          Project
          Description
          IP Address
         ILO
          Rack
          Status
              Actions

                {% for server in posts %}

            {{ server.ServerName }}
            {{ server.Owner }}
            {{ server.Project }}
            {{ server.Description }}
            {{ server.IP }}
            {{ server.ILO }}
            {{ server.Rack }}

Online

            <button type="button" class="btn btn-outline-danger" data-toggle="modal" href="#delete-server-{{server.id}}"
             data-target="#Del{{server.id}}">Delete </button>
            <button type="button" class="btn btn-outline-primary" data-toggle="modal" href="#edit-server-{{server.id}}"
             data-target="#Edit{{server.id}}">   Edit             </button>

Delete Confirmation

                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                ×
                                    </button>

                                        <form action="{% url 'delete_post' server.id %}" method="post">{% csrf_token %}

Are you sure you want to delete {{ server.ServerName }}?

                                            <input type="submit" class="btn btn-danger btn-md" value="Confirm"/>
                                                <button type="submit" class="btn btn-secondary" data-dismiss="modal">Cancel</button>

                                        </form>

Edit Server {{ server.ServerName }}

                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        ×
                                </button>

                                                                        {% with server.id as server_id %}
                                                                        {% with forms|get_by_key:server_id as edit_form %}
                                        <form action="{% url 'edit_post'  server_id %}" method="post"> {% csrf_token %}

                                        {% for field in forms.server_id %}

                                                {{ field.errors }}

                                {{ field.html_name }}
 {{ field }}

                                                {% if field.help_text %}

{{ field.help_text|safe }}

                                                {% endif %}

                                                {% endfor %}

<button type="submit" class="save btn btn-success btn-lg">Confirm</button>

<button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal">Cancel</button>

                </form>
                {% endwith %}
                {% endwith %}

                {% endfor %}

Add Server

                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    ×
                </button>

                    <form method="post" novalidate> {% csrf_token %}

                            {% for field in form %}

                            {{ field.errors }}

                    {{ field.html_name }}
 {{ field }}

                            {% if field.help_text %}

{{ field.help_text|safe }}

                            {% endif %}

                {% endfor %}

<button type="submit" class="save btn btn-success btn-lg" >Confirm</button>

<button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal">Cancel</button>

        </form>

views.py -

# Create your views here.

from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
from django.shortcuts import render, redirect
from django.template import RequestContext
from django.views.generic import TemplateView, UpdateView, DeleteView, CreateView
from DevOpsWeb.forms import HomeForm
from DevOpsWeb.models import serverlist
from django.core.urlresolvers import reverse_lazy
from simple_search import search_filter
from django.db.models import Q

class HomeView(TemplateView):

    template_name = 'serverlist.html'

    def get(self, request):

        form = HomeForm()
        query = request.GET.get("q")
        posts = serverlist.objects.all()

        forms = {}

        if query:
            posts = serverlist.objects.filter(Q(ServerName__icontains=query) | Q(Owner__icontains=query) | Q(Project__icontains=query) | Q(Description__icontains=query) | Q(IP__icontains=query) | Q(ILO__icontains=query) | Q(Rack__icontains=query))
        else:
            posts = serverlist.objects.all()
        #for post in posts:
        #    form = HomeForm(instance=post)
        for post in posts:
            forms[post.id] = HomeForm(instance=post)
        args = {'form' : form,'forms': forms, 'posts' : posts}
        #args = {'form' : form, 'forms': forms, 'posts' : posts}
        return render(request, self.template_name, args)

    def post(self,request):
        form = HomeForm(request.POST)
        posts = serverlist.objects.all()

        if form.is_valid(): # Checks if validation of the forms passed
            post = form.save(commit=False)
            post.save()
            #form = HomeForm()
            return redirect('serverlist')
        for post in posts:
            forms[post.id] = HomeForm(instance=post)
        args = {'form' : form, 'forms': forms, 'posts' : posts}
        #args = {'form' : form,'forms': forms, 'posts' : posts}
        return render(request, self.template_name,args)

class PostDelete(DeleteView):
    model = serverlist
    success_url = reverse_lazy('serverlist')

class PostEdit(UpdateView):
    template_name = 'serverlist.html'
    model = serverlist
    form_class = HomeForm
    #fields = ['ServerName','Owner','Project','Description','IP','ILO','Rack','Status']

    success_url = reverse_lazy('serverlist')
    #def get_object(self):
    #    obj = get_object_or_404(Calification, pk=self.request.POST.get('pk'))
    #    return obj

Body:
This :

{% with server.id as server_id %}
    {# ... #}
    {{ forms.server_id.as_p }}

just cannot work - it will look for forms["server_id"] (=> use the literal string "server_id" as key). You will need a custom template filter, such as the one described here. And as Daniel Roseman rightly mentions in a comment, you'll have to pass whatever server is supposed to be to your template's context too.

Also note that you're going to get a NameError in HomeView.post - you copy-pasted part of the code filling in your posts dict but not the part instanciating it. You should really factor this out instead of copy-pasting.


问:
boost::process how to know when a process exited "gracefully or not"?
While waiting for a boost::process::child, how can you know if it exited "gracefully or not"?

Let's say I create a processus:

```<code>boost::process::child child( "myprg.exe", "5000" );
child.wait();
int res = child.exit_code();
</code>```

Where myprg.exe is:

```<code>int main( int argc, char* argv[] )
{
    if ( argc == 2 )
    {
        boost::this_thread::sleep( boost::posix_time::milliseconds( atoi( argv[1] ) ) );
        return 1;
    }

    return 0;
}
</code>```

Note: This a MCVE that makes no sense, I agree main should return 0 if successfull.

I see that if someone kills the process while it waits (using child.terminate for instance or Windows Process Manager), child.exit_code() will return 1.

So, in the end, when child.exit_code() is 1, how can I know if this is the value returned by the process's main entry function or if the process was killed?

Is it guaranteed that 1 will mean process was killed? Then program should not return 1 and keep this exit code to identify the specific situation where it was killed and did not exit cleanly?

If not, does boost::process API provide something to know if process ended up cleanly or was killed?

答:
You can set an error handler in child process to return a different exit code. For instance, add std::set_terminate from STL library :</p>

```<code>int main( int argc, char* argv[] )
{
    std::set_terminate([](){ exit(2); });
    if ( argc == 2 )
    {
        boost::this_thread::sleep(boost::posix_time::milliseconds(atoi(argv[1])));
        return 1;
    }
    return 0;
}
</code>```

Body:
While waiting for a boost::process::child, how can you know if it exited "gracefully or not"?

Let's say I create a processus:

boost::process::child child( "myprg.exe", "5000" );
child.wait();
int res = child.exit_code();

Where myprg.exe is:

int main( int argc, char* argv[] )
{
    if ( argc == 2 )
    {
        boost::this_thread::sleep( boost::posix_time::milliseconds( atoi( argv[1] ) ) );
        return 1;
    }

    return 0;
}

Note: This a MCVE that makes no sense, I agree main should return 0 if successfull.

I see that if someone kills the process while it waits (using child.terminate for instance or Windows Process Manager), child.exit_code() will return 1.

So, in the end, when child.exit_code() is 1, how can I know if this is the value returned by the process's main entry function or if the process was killed?

Is it guaranteed that 1 will mean process was killed? Then program should not return 1 and keep this exit code to identify the specific situation where it was killed and did not exit cleanly?

If not, does boost::process API provide something to know if process ended up cleanly or was killed?

Body:
You can set an error handler in child process to return a different exit code. For instance, add std::set_terminate from STL library :

int main( int argc, char* argv[] )
{
    std::set_terminate([](){ exit(2); });
    if ( argc == 2 )
    {
        boost::this_thread::sleep(boost::posix_time::milliseconds(atoi(argv[1])));
        return 1;
    }
    return 0;
}


问:
TextMesh Pro unity plugin stopped working after updating Unity to 5.6 beta
I updated Unity3D to 5.6 beta version. I had asset from store called TextMesh Pro. Now it doesn't work (no text, many NREs). Console shows:

error CS1704: An assembly with the same name `TextMeshPro' has already
  been imported. Consider removing one of the references or sign the
  assembly Assets/TextMesh Pro/Plugins/TextMeshPro.dll (Location of the
  symbol related to previous error) Assets/TextMesh
  Pro/Plugins/Runtime-Only DLL/TextMeshPro.dll (Location of the symbol
  related to previous error)

I did not import this twice. The changelog of Unity 5.6 says that this asset will be built in in unity, but it is not yet. Is there any workaround or fix for something like this?

答:
Here is another approach which works.

Open your project folder go to Assets and delete the whole folder of TextMesh Pro.

After that go to:

C:\Users\YOUR_USERNAME\AppData\Roaming\Unity\Asset Store-UNITY_VERSION_HERE\Unity Technologies\Unity EssentialsBeta Content and delete TextMesh Pro.unitypackage

After that go to Asset store and you will be able to download the latest version which works without problems on Unity 2017.2.

ContentLicense: CC BY-SA 4.0


问:
ASP.NET MVC Viewmodel Edit returns empty fields (item is not identified by id)
I previously reveived some help here but some problems with the "Edit" arouse now. Currently stuck at HttpGet, HttpPost is yet to come.

In short, whenever I click on an existing item to edit, instead of the expected values, it returns an empty form, as seen here. (You might think that the reason for this is because I use the same exact view for Create and Edit but unfortunately this isn't, even when I used to separate ones, had the same result.)

Town.cs

```<code>using System.Collections.Generic;

namespace City.Models
{
    public class Town
    {
        public Town()
        {
            Streets = new List<Street>();
        }
        public int TownId { get; set; }
        public string TownName { get; set; }
        public virtual ICollection<Street> Streets { get; set; }
    }
}
</code>```

Street.cs

```<code>using System.Collections.Generic;

namespace City.Models
{
    public class Street
    {
        public Street()
        {
            Houses = new List<House>();
        }
        public int StreetId { get; set; }
        public string StreetName { get; set; }
        public virtual ICollection<House> Houses { get; set; }
    }
}
</code>```

House.cs

```<code>using System.Collections.Generic;

namespace City.Models
{
    public class House
    {
        public House()
        {
            Floors = new List<Floor>();
        }
        public int HouseId { get; set; }
        public string HouseName { get; set; }
        public ICollection<Floor> Floors { get; set; }
    }
}
</code>```

Floor.cs

```<code>using System.Collections.Generic;

namespace City.Models
{
    public class Floor
    {
        public Floor()
        {
            FireExtinguishers = new List<FireExtinguisher>();
        }
        public int FloorId { get; set; }
        public int FloorNumber { get; set; }
        public virtual ICollection<FireExtinguisher> FireExtinguishers { get; set; }
    }
}
</code>```

FireExtinguisher.cs

```<code>using System.ComponentModel;

namespace City.Models
{
    public class FireExtinguisher
    {
        public int FireExtinguisherId { get; set; }
        [DisplayName("Fire Extinguisher")]
        public string FireExtinguisherName { get; set; }
        public int FloorId { get; set; }
        public int HouseId { get; set; }
        public int StreetId { get; set; }
        public int TownId { get; set; }
        public Floor Floor { get; set; }
        public House House { get; set; }
        public Street Street { get; set; }
        public Town Town { get; set; }
    }
}
</code>```

MyViewModel.cs

```<code>using System.Collections.Generic;

namespace City.Models
{
    public class MyViewModel
    {
        public IEnumerable<Town> TownId { get; set; }
        public IEnumerable<Street> StreetId { get; set; }
        public IEnumerable<House> HouseId { get; set; }
        public IEnumerable<Floor> FloorId { get; set; }
        public FireExtinguisher FireExtinguisher { get; set; }
        public string FireExtinguisherName { get; set; }
    }
}
</code>```

Create/Edit view

```<code>@model City.Models.MyViewModel

<h2>Add new or edit existing FE</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="col-md-12">

            <div class="form-group">
                @Html.LabelFor(model => model.TownId, "Town", new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.TownId, new SelectList(Model.TownId, "TownId", "TownName"), "Choose Town", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.TownId, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.StreetId, "Street", new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.StreetId, new SelectList(Model.StreetId, "StreetId", "StreetName"), "Choose Street", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.StreetId, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.HouseId, "House", new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.HouseId, new SelectList(Model.HouseId, "HouseId", "HouseName"), "Choose House", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.HouseId, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FloorId, "Floor", new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.FloorId, new SelectList(Model.FloorId, "FloorId", "FloorNumber"), "Choose Floor", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.FloorId, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FireExtinguisherName, "Fire Extinguisher", new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.FireExtinguisherName, new { @class = "form-control", Value = "" })
                    @Html.ValidationMessageFor(model => model.FireExtinguisherName, "", new { @class = "text-danger" })
                </div>
            </div>

        </div>

        <div>
            <div>
                <input type="submit" value="Do it" class="btn btn-default" />
            </div>
        </div>
    </div>

}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
</code>```

Homecontroller.cs

```<code>using System;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using City.Models;

namespace City.Controllers
{
    public class HomeController : Controller
    {
        private ApplicationDbContext db;
        private MyViewModel viewModel;

        public HomeController()
        {
            db = new ApplicationDbContext();

            var town = db.Towns.ToList();
            var street = db.Streets.ToList();
            var house = db.Houses.ToList();
            var floor = db.Floors.ToList();

            viewModel = new MyViewModel()
            {
                TownId = town,
                StreetId = street,
                HouseId = house,
                FloorId = floor
            };
        }
        public ActionResult Index()
        {
            return View(db.FireExtinguishers.ToList());
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View(viewModel);
        }

        [HttpPost]
        public ActionResult Create(FireExtinguisher fe)
        {
            if (ModelState.IsValid)
            {
                db.FireExtinguishers.Add(fe);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(viewModel);
        }

        [HttpGet]
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var fe = db.FireExtinguishers.Find(id);

            var town = db.Towns.ToList();
            var street = db.Streets.ToList();
            var house = db.Houses.ToList();
            var floor = db.Floors.ToList();

            viewModel = new MyViewModel()
            {
                FireExtinguisher = fe,

                TownId = town,
                StreetId = street,
                HouseId = house,
                FloorId = floor
            };
            return View("Create", viewModel);
        }

        [HttpPost]
        public ActionResult Edit()
        {
            throw new NotImplementedException();
        }
    }
}
</code>```

Any help would be appreciated, thank you

答:
Personally I like to use View- and Post-Models for that as a clear statement, what is send to the View (ViewModel) and what is send back via Post. As a naming convention the name of the model class Takes the controller name and the action name.

I start with the PostModel, which would be in your case

```<code>public class HomeEditPostModel
{
    [Required]
    [MaxLength(50)]
    public string Name { get; set; }
    [Required]
    public int TownId { get; set; }
    [Required]
    public int StreetId { get; set; }
    [Required]
    public int HouseId { get; set; }
    [Required]
    public int FloorId { get; set; }
}
</code>```

Now for the view we need some collections for the dropdown fields, where we can select from

```<code>public class SelectionItem<TKey>
{
    public TKey Key { get; set; }
    public string DisplayName { get; set; }
}

public class HomeEditViewModel : HomeEditPostModel
{
    public IEnumerable<SelectionItem<int>> Town { get; set; }
    public IEnumerable<SelectionItem<int>> Street { get; set; }
    public IEnumerable<SelectionItem<int>> House { get; set; }
    public IEnumerable<SelectionItem<int>> Floor { get; set; }
}
</code>```

Now the view

```<code>@model WebApplication6.Models.HomeEditViewModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>HomeEditSubmitModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TownId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.TownId, new SelectList(Model.Town, "Key", "DisplayName"), "Choose Town", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TownId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.StreetId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.StreetId, new SelectList(Model.Street, "Key", "DisplayName"), "Choose Street", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.StreetId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.HouseId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.HouseId, new SelectList(Model.House, "Key", "DisplayName"), "Choose House", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.HouseId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.FloorId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.FloorId, new SelectList(Model.Floor, "Key", "DisplayName"), "Choose Floor", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.FloorId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
</code>```

and finally the controller (only relevant parts)

```<code>public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Edit(int id)
    {
        // just some fake data for demonstration
        var model = new HomeEditViewModel
        {
            Name = "Name",
            Floor = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Floor {e}" }),
            Street = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Street {e}" }),
            House = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"House {e}" }),
            Town = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Town {e}" }),

            FloorId = 3,
            StreetId = 4,
            HouseId = 5,
            TownId = 6,
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Edit(int id, HomeEditPostModel model)
    {
        // needs to save the data here

        return RedirectToAction(nameof(Index));
    }
}
</code>```

Body:
I previously reveived some help here but some problems with the "Edit" arouse now. Currently stuck at HttpGet, HttpPost is yet to come.

In short, whenever I click on an existing item to edit, instead of the expected values, it returns an empty form, as seen here. (You might think that the reason for this is because I use the same exact view for Create and Edit but unfortunately this isn't, even when I used to separate ones, had the same result.)

Town.cs

using System.Collections.Generic;

namespace City.Models
{
    public class Town
    {
        public Town()
        {
            Streets = new List<Street>();
        }
        public int TownId { get; set; }
        public string TownName { get; set; }
        public virtual ICollection<Street> Streets { get; set; }
    }
}

Street.cs

using System.Collections.Generic;

namespace City.Models
{
    public class Street
    {
        public Street()
        {
            Houses = new List<House>();
        }
        public int StreetId { get; set; }
        public string StreetName { get; set; }
        public virtual ICollection<House> Houses { get; set; }
    }
}

House.cs

using System.Collections.Generic;

namespace City.Models
{
    public class House
    {
        public House()
        {
            Floors = new List<Floor>();
        }
        public int HouseId { get; set; }
        public string HouseName { get; set; }
        public ICollection<Floor> Floors { get; set; }
    }
}

Floor.cs

using System.Collections.Generic;

namespace City.Models
{
    public class Floor
    {
        public Floor()
        {
            FireExtinguishers = new List<FireExtinguisher>();
        }
        public int FloorId { get; set; }
        public int FloorNumber { get; set; }
        public virtual ICollection<FireExtinguisher> FireExtinguishers { get; set; }
    }
}

FireExtinguisher.cs

using System.ComponentModel;

namespace City.Models
{
    public class FireExtinguisher
    {
        public int FireExtinguisherId { get; set; }
        [DisplayName("Fire Extinguisher")]
        public string FireExtinguisherName { get; set; }
        public int FloorId { get; set; }
        public int HouseId { get; set; }
        public int StreetId { get; set; }
        public int TownId { get; set; }
        public Floor Floor { get; set; }
        public House House { get; set; }
        public Street Street { get; set; }
        public Town Town { get; set; }
    }
}

MyViewModel.cs

using System.Collections.Generic;

namespace City.Models
{
    public class MyViewModel
    {
        public IEnumerable<Town> TownId { get; set; }
        public IEnumerable<Street> StreetId { get; set; }
        public IEnumerable<House> HouseId { get; set; }
        public IEnumerable<Floor> FloorId { get; set; }
        public FireExtinguisher FireExtinguisher { get; set; }
        public string FireExtinguisherName { get; set; }
    }
}

Create/Edit view

@model City.Models.MyViewModel

Add new or edit existing FE

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

                @Html.LabelFor(model => model.TownId, "Town", new { @class = "control-label col-md-2" })

                    @Html.DropDownListFor(model => model.TownId, new SelectList(Model.TownId, "TownId", "TownName"), "Choose Town", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.TownId, "", new { @class = "text-danger" })

                @Html.LabelFor(model => model.StreetId, "Street", new { @class = "control-label col-md-2" })

                    @Html.DropDownListFor(model => model.StreetId, new SelectList(Model.StreetId, "StreetId", "StreetName"), "Choose Street", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.StreetId, "", new { @class = "text-danger" })

                @Html.LabelFor(model => model.HouseId, "House", new { @class = "control-label col-md-2" })

                    @Html.DropDownListFor(model => model.HouseId, new SelectList(Model.HouseId, "HouseId", "HouseName"), "Choose House", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.HouseId, "", new { @class = "text-danger" })

                @Html.LabelFor(model => model.FloorId, "Floor", new { @class = "control-label col-md-2" })

                    @Html.DropDownListFor(model => model.FloorId, new SelectList(Model.FloorId, "FloorId", "FloorNumber"), "Choose Floor", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.FloorId, "", new { @class = "text-danger" })

                @Html.LabelFor(model => model.FireExtinguisherName, "Fire Extinguisher", new { @class = "control-label col-md-2" })

                    @Html.TextBoxFor(model => model.FireExtinguisherName, new { @class = "form-control", Value = "" })
                    @Html.ValidationMessageFor(model => model.FireExtinguisherName, "", new { @class = "text-danger" })

                <input type="submit" value="Do it" class="btn btn-default" />

}

    @Html.ActionLink("Back to List", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Homecontroller.cs

using System;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using City.Models;

namespace City.Controllers
{
    public class HomeController : Controller
    {
        private ApplicationDbContext db;
        private MyViewModel viewModel;

        public HomeController()
        {
            db = new ApplicationDbContext();

            var town = db.Towns.ToList();
            var street = db.Streets.ToList();
            var house = db.Houses.ToList();
            var floor = db.Floors.ToList();

            viewModel = new MyViewModel()
            {
                TownId = town,
                StreetId = street,
                HouseId = house,
                FloorId = floor
            };
        }
        public ActionResult Index()
        {
            return View(db.FireExtinguishers.ToList());
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View(viewModel);
        }

        [HttpPost]
        public ActionResult Create(FireExtinguisher fe)
        {
            if (ModelState.IsValid)
            {
                db.FireExtinguishers.Add(fe);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(viewModel);
        }

        [HttpGet]
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var fe = db.FireExtinguishers.Find(id);

            var town = db.Towns.ToList();
            var street = db.Streets.ToList();
            var house = db.Houses.ToList();
            var floor = db.Floors.ToList();

            viewModel = new MyViewModel()
            {
                FireExtinguisher = fe,

                TownId = town,
                StreetId = street,
                HouseId = house,
                FloorId = floor
            };
            return View("Create", viewModel);
        }

        [HttpPost]
        public ActionResult Edit()
        {
            throw new NotImplementedException();
        }
    }
}

Any help would be appreciated, thank you

Body:
Personally I like to use View- and Post-Models for that as a clear statement, what is send to the View (ViewModel) and what is send back via Post. As a naming convention the name of the model class Takes the controller name and the action name.

I start with the PostModel, which would be in your case

public class HomeEditPostModel
{
    [Required]
    [MaxLength(50)]
    public string Name { get; set; }
    [Required]
    public int TownId { get; set; }
    [Required]
    public int StreetId { get; set; }
    [Required]
    public int HouseId { get; set; }
    [Required]
    public int FloorId { get; set; }
}

Now for the view we need some collections for the dropdown fields, where we can select from

public class SelectionItem<TKey>
{
    public TKey Key { get; set; }
    public string DisplayName { get; set; }
}

public class HomeEditViewModel : HomeEditPostModel
{
    public IEnumerable<SelectionItem<int>> Town { get; set; }
    public IEnumerable<SelectionItem<int>> Street { get; set; }
    public IEnumerable<SelectionItem<int>> House { get; set; }
    public IEnumerable<SelectionItem<int>> Floor { get; set; }
}

Now the view

@model WebApplication6.Models.HomeEditViewModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>HomeEditSubmitModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TownId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.TownId, new SelectList(Model.Town, "Key", "DisplayName"), "Choose Town", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TownId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.StreetId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.StreetId, new SelectList(Model.Street, "Key", "DisplayName"), "Choose Street", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.StreetId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.HouseId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.HouseId, new SelectList(Model.House, "Key", "DisplayName"), "Choose House", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.HouseId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.FloorId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.FloorId, new SelectList(Model.Floor, "Key", "DisplayName"), "Choose Floor", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.FloorId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

and finally the controller (only relevant parts)

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Edit(int id)
    {
        // just some fake data for demonstration
        var model = new HomeEditViewModel
        {
            Name = "Name",
            Floor = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Floor {e}" }),
            Street = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Street {e}" }),
            House = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"House {e}" }),
            Town = Enumerable.Range(1, 10).Select(e => new SelectionItem<int> { Key = e, DisplayName = $"Town {e}" }),

            FloorId = 3,
            StreetId = 4,
            HouseId = 5,
            TownId = 6,
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Edit(int id, HomeEditPostModel model)
    {
        // needs to save the data here

        return RedirectToAction(nameof(Index));
    }
}