问:
InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images
Using some pretty stock standard C# code to resize an image, and place it on a coloured background

```<code>Image imgToResize = Image.FromFile(@"Dejeuner.jpg");
Size size = new Size(768, 1024);
Bitmap b = new Bitmap(size.Width, size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height);

g.DrawImage(imgToResize, new Rectangle(0,150,768, 570));
b.Save("sized_HighQualityBicubic.jpg");
</code>```

The result has a funny artefact in the 0th and 1st columns of pixels.  The 0th column appears to be mixed with the background colour, and the 1st column has been made lighter.

See the top left corner zoomed for high quality bicubic and bicubic.

..and HighQualityBilinear

This forum post appears to be someone with the same problem: DrawImage with sharp edges

The sounds like a bug to me? I can understand why the colours would mix at the top of the resized image.  But mixing the colours on the left / right edges doesn't make sense.  Does anyone know of a fix to prevent these artefacts?

Update: very similar conversation going on in the comments here: GDI+ InterpolationMode

答:
Below is the resulting image of typical HighQualityBicubic resizing (drawn over white background).

You can see semi-transparent pixels at edge lines. You can call it a bug. I think it is just a technical detail of the GDI+. And it is simple to workaround this artifact.

1) Prevent anti-aliasing.

```<code>...
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
// add below line
g.CompositingMode = CompositingMode.SourceCopy;
...
</code>```

With CompositingMode.SourceCopy result image will show visible outline but not anti-aliased with background pixels.

2) Crop semi-transparent area

You can ignore those semi-transparent pixels altogether.

```<code>Image imgToResize = Image.FromFile(@"Dejeuner.jpg");
Size size = new Size(768, 1024);
Bitmap b = new Bitmap(size.Width, size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height);

Bitmap b2 = new Bitmap(768 + 8, 570 + 8);
{
    Graphics g2 = Graphics.FromImage((Image)b2);
    g2.Clear(Color.White);
    g2.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g2.DrawImage(imgToResize, new Rectangle(2, 2, 768 + 4, 570 + 4));
}

g.CompositingMode = CompositingMode.SourceCopy;
g.DrawImage(b2, 0, 150, new Rectangle(4, 4, 768, 570), GraphicsUnit.Pixel);
b.Save("sized_HighQualityBicubic.jpg");
</code>```

Body:
Using some pretty stock standard C# code to resize an image, and place it on a coloured background

Image imgToResize = Image.FromFile(@"Dejeuner.jpg");
Size size = new Size(768, 1024);
Bitmap b = new Bitmap(size.Width, size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height);

g.DrawImage(imgToResize, new Rectangle(0,150,768, 570));
b.Save("sized_HighQualityBicubic.jpg");

The result has a funny artefact in the 0th and 1st columns of pixels.  The 0th column appears to be mixed with the background colour, and the 1st column has been made lighter.

See the top left corner zoomed for high quality bicubic and bicubic.

..and HighQualityBilinear

This forum post appears to be someone with the same problem: DrawImage with sharp edges

The sounds like a bug to me? I can understand why the colours would mix at the top of the resized image.  But mixing the colours on the left / right edges doesn't make sense.  Does anyone know of a fix to prevent these artefacts?

Update: very similar conversation going on in the comments here: GDI+ InterpolationMode

Body:
Below is the resulting image of typical HighQualityBicubic resizing (drawn over white background).

You can see semi-transparent pixels at edge lines. You can call it a bug. I think it is just a technical detail of the GDI+. And it is simple to workaround this artifact.

1) Prevent anti-aliasing.

...
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
// add below line
g.CompositingMode = CompositingMode.SourceCopy;
...

With CompositingMode.SourceCopy result image will show visible outline but not anti-aliased with background pixels.

2) Crop semi-transparent area

You can ignore those semi-transparent pixels altogether.

Image imgToResize = Image.FromFile(@"Dejeuner.jpg");
Size size = new Size(768, 1024);
Bitmap b = new Bitmap(size.Width, size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height);

Bitmap b2 = new Bitmap(768 + 8, 570 + 8);
{
    Graphics g2 = Graphics.FromImage((Image)b2);
    g2.Clear(Color.White);
    g2.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g2.DrawImage(imgToResize, new Rectangle(2, 2, 768 + 4, 570 + 4));
}

g.CompositingMode = CompositingMode.SourceCopy;
g.DrawImage(b2, 0, 150, new Rectangle(4, 4, 768, 570), GraphicsUnit.Pixel);
b.Save("sized_HighQualityBicubic.jpg");


来源: stackexchange

问:
Cannot connect to the Docker daemon when running with sudo
My Docker service is up and running. However when attempting to use Docker by running it with sudo, e.g.:

```<code>12:40:26/~ $ sudo docker pull fluxcapacitor/pipeline
Using default tag: latest
</code>```

I have got the following error:

```<code>Warning: failed to get default registry endpoint from daemon (Cannot connect to
the Docker daemon. Is the docker daemon running on this host?). Using system
default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
</code>```

Note that I had already followed the answers on Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host?

as follows:

docker-machine start default

```<code>12:40:36/~ $ docker-machine start default
Starting "default"...
Machine "default" is already running.
</code>```

docker ps

```<code>12:41:20/~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
</code>```

So what more needs to be done?

This is:

```<code>$ docker --version
Docker version 1.11.2, build b9f10c9
</code>```

on El Capitan.

Output of docker-machine env default

```<code>$ eval "$(docker-machine env default)"

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/macuser/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
</code>```

答:
I had same probelem on my MAC, when attempted

```<code># eval "$(docker-machine env default)"
</code>```

got this error

```<code>Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": x509: certificate is valid for 192.168.99.101, not 192.168.99.100
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
</code>```

to regenerate certificates, find out the docker-machines available;

```<code># docker-machine ls
</code>```

Output of avalable docker machines (omitted others)

```<code>NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default       -        virtualbox   Running   tcp://192.168.99.100:2376           Unknown   Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate is valid for 192.168.99.101, not 192.168.99.100
</code>```

Generate certificates for this default docker-machine

```<code># docker-machine regenerate-certs default
</code>```

and then setup docker-machine env to default docker-machine;

```<code># eval "$(docker-machine env default)"
</code>```

and it works normally after that.

ContentLicense: CC BY-SA 3.0

Body:
My Docker service is up and running. However when attempting to use Docker by running it with sudo, e.g.:

12:40:26/~ $ sudo docker pull fluxcapacitor/pipeline
Using default tag: latest

I have got the following error:

Warning: failed to get default registry endpoint from daemon (Cannot connect to
the Docker daemon. Is the docker daemon running on this host?). Using system
default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Note that I had already followed the answers on Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host?

as follows:

docker-machine start default

12:40:36/~ $ docker-machine start default
Starting "default"...
Machine "default" is already running.

docker ps

12:41:20/~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

So what more needs to be done?

This is:

$ docker --version
Docker version 1.11.2, build b9f10c9

on El Capitan.

Output of docker-machine env default

$ eval "$(docker-machine env default)"

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/macuser/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"

Body:
I had same probelem on my MAC, when attempted

# eval "$(docker-machine env default)"

got this error

Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": x509: certificate is valid for 192.168.99.101, not 192.168.99.100
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.

to regenerate certificates, find out the docker-machines available;

# docker-machine ls

Output of avalable docker machines (omitted others)

NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default       -        virtualbox   Running   tcp://192.168.99.100:2376           Unknown   Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate is valid for 192.168.99.101, not 192.168.99.100

Generate certificates for this default docker-machine

# docker-machine regenerate-certs default

and then setup docker-machine env to default docker-machine;

# eval "$(docker-machine env default)"

and it works normally after that.


问:
Is there any good way to check the pdf file is same as word document?
There is a problem that I use vba to print word document to pdf file but the pdf files sometimes are not same as word.

Example.

1.The pdf file page is not same as word document page.

The Word Document is 10 pages.

The PDF file is 9 pages.

2.Word Document will just print the half to pdf.

The last page of word document maybe is 200 words but the pdf file only have 120 words.

I have a way to check this problem.

1.Check the page.

2.Check the last ten word is the same or not.

But there is a problem that the special symbol like "≦" can't be read by vba and can't be read by Acrobat API.

Any idea can handle it?

答:
Instead of "≦" use "<=".
If you have Acrobat.tlb reference than the number of pages is something like

```<code>Dim oPapp As Acrobat.AcroApp
Dim oPDDoc As Acrobat.AcroPDDoc
Dim docPages as Long
Set oPapp = CreateObject("AcroExch.App")
Set oPDDoc = CreateObject("AcroExch.PDDoc")
oPDDoc.Open ("C:\test.pdf")
docPages = oPDDoc.numPages
</code>```

Body:
Instead of "≦" use "<=".
If you have Acrobat.tlb reference than the number of pages is something like

Dim oPapp As Acrobat.AcroApp
Dim oPDDoc As Acrobat.AcroPDDoc
Dim docPages as Long
Set oPapp = CreateObject("AcroExch.App")
Set oPDDoc = CreateObject("AcroExch.PDDoc")
oPDDoc.Open ("C:\test.pdf")
docPages = oPDDoc.numPages


问:
I study Python on Windows ,random.shuffle(), a function was be readed as a atrribute,what's wrong?
This is the Picture with BUGS It is ok on Python IDLE, but wrong on commandLine, is there anything wrong? Python version 3.6.4, win10 64bit, thanks for you to guide me, I am new with Python, the example is on the book PYTHON FOR KIDS, Jason Briggs</p>

答: Change the file name from random.py to studyrandom.py, filename is same to the module, so it is wrong</p>


问:
How to use V8's built in functions
I'm new in both javascript and V8. According to Google's Embedder's Guide, I saw something in the context section talking about built-in utility javascript functions. And I also found some .js files(e.g. math.js) in the downloaded source code, so I tried to write a simple program to call functions in these files, but I failed.

Does a context created by Persistent<Context> context = Context::New() have any built-in js functions? How can I access them?

Is there a way to first import existing js files as a library(something like src="xxx" type="text/javascript" in HTML page) and then run my own execute script?

Can I call google maps api through the embedded V8 library in app? How?

答:
I think v8 gives you the Math.* functions for free.

You need to implement everything else yourself though, like loading other javascript files. shell.cc has some of the functions you might be looking for.

As for the maps API, I believe you would need a full blown rendering engine/javascript engine combo for that. You might be better off taking a look at Webkit or something that you can use to embed Webkit for what you're looking to do, I can't really say.

ContentLicense: CC BY-SA 2.5

Title: How to use V8's built in functions


问:
Icons at the bottom of the navbar not moving according to the resizing of the frame

I am trying to position something at the bottom of the navbar.

Sample code: https://jsfiddle.net/545cdqb2/1/

Having trouble with this part of the code.

```<code>.push-to-bottom
{
  position: absolute;
  bottom: 0px;
  height: 100px;
  width: 100%;
}
</code>```

Upon resizing of the frame, the "red div" hides the navbar elements behind it and I'm unable to click on them.

Issue screenshot

答:
Use this.

.push-to-bottom {
  position: absolute;
  bottom: 0px;
  height: 100px;
  width: 100%;
}

/* https://github.com/samrayner/bootstrap-side-navbar#css */

@media (max-width: 768px) {
  .navbar-fixed-side {
    margin-left: -15px;
    margin-right: -15px
  }
}

@media (min-width: 768px) {
  .navbar-fixed-side {
    position: fixed;
    margin: 0 -15px;
    height: 100vh;
    width: inherit;
    overflow: auto;
    border-top-width: 0;
    border-bottom-width: 0;
    border-radius: 0
  }
  .navbar-fixed-side .container,
  .navbar-fixed-side .container-fluid {
    width: auto;
    padding-left: 0;
    padding-right: 0
  }
  .navbar-fixed-side .navbar-header {
    float: none
  }
  .navbar-fixed-side .navbar-brand {
    height: auto
  }
  .navbar-fixed-side>.container .navbar-brand,
  .navbar-fixed-side>.container-fluid .navbar-brand {
    margin-left: 0
  }
  .navbar-fixed-side .navbar-collapse {
    width: 100%;
    border-top: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-nav {
    float: none;
    margin: 0 -15px
  }
  .navbar-fixed-side .navbar-nav>li {
    float: none
  }
  .navbar-fixed-side .navbar-nav>li>a {
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-form {
    margin: 0;
    margin-left: -15px;
    margin-right: -15px;
    padding: 10px 15px;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-text {
    float: none;
    margin-left: 0;
    margin-right: 0
  }
  .navbar-fixed-side .navbar-left,
  .navbar-fixed-side .navbar-right {
    float: none !important
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu {
    position: static;
    float: none;
    width: auto;
    margin-top: 0;
    background-color: transparent;
    border: 0;
    box-shadow: none;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a,
  .navbar-fixed-side .navbar-nav .dropdown-menu .dropdown-header {
    padding: 5px 15px 5px 25px
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a {
    line-height: 20px;
    color: #777
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:hover,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:focus {
    background-image: none
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>.active>a {
    background-color: #e7e7e7;
    color: #555
  }
  .navbar-fixed-side .navbar-nav>li>a:hover,
  .navbar-fixed-side .navbar-nav>li>a:focus,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:hover,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:focus {
    background-color: #f0f0f0;
    color: #333
  }
  .navbar-fixed-side .dropdown>.dropdown-toggle,
  .navbar-fixed-side .dropdown-menu>.dropdown-header {
    background-color: transparent !important;
    color: #9d9d9d !important;
    cursor: default;
    font-size: 0.8em;
    text-transform: uppercase;
    border-bottom: none;
    padding-bottom: 0
  }
  .navbar-fixed-side .dropdown-toggle .caret {
    display: none
  }
  .navbar-fixed-side .dropdown-menu {
    display: block
  }
  .navbar-fixed-side.navbar-inverse .navbar-collapse,
  .navbar-fixed-side.navbar-inverse .navbar-nav>li>a,
  .navbar-fixed-side.navbar-inverse .navbar-form,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu {
    border-color: #363636
  }
  .navbar-fixed-side.navbar-inverse .divider {
    background-color: #363636
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li>a {
    color: #9d9d9d
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>.active>a {
    background-color: #090909;
    color: #fff
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav>li:not(.active)>a:hover,
  .navbar-fixed-side.navbar-inverse .navbar-nav>li:not(.active)>a:focus,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li:not(.active)>a:hover,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li:not(.active)>a:focus {
    background-color: #2f2f2f;
    color: #fff
  }
  .navbar-fixed-side.navbar-inverse .dropdown>.dropdown-toggle {
    color: #777777 !important
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-lg-2">
        <nav id="side-navbar" class="navbar navbar-default navbar-fixed-side">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>

                                Brand Name

            </div>
            <div id="navbar" class="navbar-collapse collapse">
              <ul class="nav navbar-nav navbar-font-family">
                <li>Nav 1</li>
                <li>Nav 2</li>
                <li>Nav 3</li>
                <li>Nav 4</li>
                <li>Nav 5</li>
                <li>Nav 6</li>
                <li>Nav 7</li>
              </ul>
            </div>

                            Hello!

          </div>
        </nav>
      </div>
      <div class="col-sm-9 col-lg-10">
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
      </div>
    </div>
  </div>
</body></code>```

Body:
I am trying to position something at the bottom of the navbar.

Sample code: https://jsfiddle.net/545cdqb2/1/

Having trouble with this part of the code.

.push-to-bottom
{
  position: absolute;
  bottom: 0px;
  height: 100px;
  width: 100%;
}

Upon resizing of the frame, the "red div" hides the navbar elements behind it and I'm unable to click on them.

Issue screenshot

Body:
Use this.

.push-to-bottom {
  position: absolute;
  bottom: 0px;
  height: 100px;
  width: 100%;
}

/* https://github.com/samrayner/bootstrap-side-navbar#css */

@media (max-width: 768px) {
  .navbar-fixed-side {
    margin-left: -15px;
    margin-right: -15px
  }
}

@media (min-width: 768px) {
  .navbar-fixed-side {
    position: fixed;
    margin: 0 -15px;
    height: 100vh;
    width: inherit;
    overflow: auto;
    border-top-width: 0;
    border-bottom-width: 0;
    border-radius: 0
  }
  .navbar-fixed-side .container,
  .navbar-fixed-side .container-fluid {
    width: auto;
    padding-left: 0;
    padding-right: 0
  }
  .navbar-fixed-side .navbar-header {
    float: none
  }
  .navbar-fixed-side .navbar-brand {
    height: auto
  }
  .navbar-fixed-side>.container .navbar-brand,
  .navbar-fixed-side>.container-fluid .navbar-brand {
    margin-left: 0
  }
  .navbar-fixed-side .navbar-collapse {
    width: 100%;
    border-top: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-nav {
    float: none;
    margin: 0 -15px
  }
  .navbar-fixed-side .navbar-nav>li {
    float: none
  }
  .navbar-fixed-side .navbar-nav>li>a {
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-form {
    margin: 0;
    margin-left: -15px;
    margin-right: -15px;
    padding: 10px 15px;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-text {
    float: none;
    margin-left: 0;
    margin-right: 0
  }
  .navbar-fixed-side .navbar-left,
  .navbar-fixed-side .navbar-right {
    float: none !important
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu {
    position: static;
    float: none;
    width: auto;
    margin-top: 0;
    background-color: transparent;
    border: 0;
    box-shadow: none;
    border-bottom: 1px solid #e7e7e7
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a,
  .navbar-fixed-side .navbar-nav .dropdown-menu .dropdown-header {
    padding: 5px 15px 5px 25px
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a {
    line-height: 20px;
    color: #777
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:hover,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:focus {
    background-image: none
  }
  .navbar-fixed-side .navbar-nav .dropdown-menu>.active>a {
    background-color: #e7e7e7;
    color: #555
  }
  .navbar-fixed-side .navbar-nav>li>a:hover,
  .navbar-fixed-side .navbar-nav>li>a:focus,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:hover,
  .navbar-fixed-side .navbar-nav .dropdown-menu>li>a:focus {
    background-color: #f0f0f0;
    color: #333
  }
  .navbar-fixed-side .dropdown>.dropdown-toggle,
  .navbar-fixed-side .dropdown-menu>.dropdown-header {
    background-color: transparent !important;
    color: #9d9d9d !important;
    cursor: default;
    font-size: 0.8em;
    text-transform: uppercase;
    border-bottom: none;
    padding-bottom: 0
  }
  .navbar-fixed-side .dropdown-toggle .caret {
    display: none
  }
  .navbar-fixed-side .dropdown-menu {
    display: block
  }
  .navbar-fixed-side.navbar-inverse .navbar-collapse,
  .navbar-fixed-side.navbar-inverse .navbar-nav>li>a,
  .navbar-fixed-side.navbar-inverse .navbar-form,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu {
    border-color: #363636
  }
  .navbar-fixed-side.navbar-inverse .divider {
    background-color: #363636
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li>a {
    color: #9d9d9d
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>.active>a {
    background-color: #090909;
    color: #fff
  }
  .navbar-fixed-side.navbar-inverse .navbar-nav>li:not(.active)>a:hover,
  .navbar-fixed-side.navbar-inverse .navbar-nav>li:not(.active)>a:focus,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li:not(.active)>a:hover,
  .navbar-fixed-side.navbar-inverse .navbar-nav .dropdown-menu>li:not(.active)>a:focus {
    background-color: #2f2f2f;
    color: #fff
  }
  .navbar-fixed-side.navbar-inverse .dropdown>.dropdown-toggle {
    color: #777777 !important
  }
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-lg-2">
        <nav id="side-navbar" class="navbar navbar-default navbar-fixed-side">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
              <a href="#">
                                Brand Name
                            </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
              <ul class="nav navbar-nav navbar-font-family">
                <li><a href="#">Nav 1</a></li>
                <li><a href="#">Nav 2</a></li>
                <li><a href="#">Nav 3</a></li>
                <li><a href="#">Nav 4</a></li>
                <li><a href="#">Nav 5</a></li>
                <li><a href="#">Nav 6</a></li>
                <li><a href="#">Nav 7</a></li>
              </ul>
            </div>
            <a align="center" href="#" class="hidden-xs push-to-bottom" style="background-color: red; color: black;">
                            Hello!
                        </a>
          </div>
        </nav>
      </div>
      <div class="col-sm-9 col-lg-10">
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
        <p>Hello World</p>
      </div>
    </div>
  </div>
</body>


问:
HTML colspan and rowspan not working
I have got a table 18 columns by 7 rows and i want to make td element to take 10 columns and 3 rows,so here is my code

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18

      1

        Protons

      2

      3

        4

        5

        6

        7

```

As you see bigInfo has an attribute of colspan equal to 10 and rowspan equal to 3,but unfortunately i only get cell 6 by 70 with a padding of 1 while i want that row to take a width of 10 columns and 3 rows.

答:
Your code wasn't valid, you had some missing tags. Additional there is no
 tag at all, don't know how your fully code is looking, but i updated it and it seems to work how it should!

```<code><table>
  <thead>
    <tr>
      <td class="groups group1">1</td>
      <td class="groups group2">2</td>
      <td class="groups group3">3</td>
      <td class="groups group4">4</td>
      <td class="groups group5">5</td>
      <td class="groups group6">6</td>
      <td class="groups group7">7</td>
      <td class="groups group8">8</td>
      <td class="groups group9">9</td>
      <td class="groups group10">10</td>
      <td class="groups group11">11</td>
      <td class="groups group12">12</td>
      <td class="groups group13">13</td>
      <td class="groups group14">14</td>
      <td class="groups group15">15</td>
      <td class="groups group16">16</td>
      <td class="groups group17">17</td>
      <td class="groups group18">18</td>
    </tr>
  </thead>
  <tbody>
    <tr class="periods period1">
        <th>1</th>
        <td class="element" id="H"></td>
        <td class="basic_info">
            <span class="info_big"></span>
            <span class="info_spans">Protons</span>
        </td>
        <td class="biginfo" colspan="10" rowspan="3"></td>
        <td class="element" id="He"></td>
    </tr>
    <tr class="periods period2">
        <th>2</th>
        <td class="element" id="Li"></td>
        <td class="element" id="Be"></td>
    </tr>
    <tr class="periods period3">
        <th>3</th>
        <td class="element" id="Na"></td>
        <td class="element" id="Mg"></td>
        <td class="element" id="Al"></td>
        <td class="element" id="Si"></td>
    </tr>
    <tr class="periods period4">
        <th>4</th>
    <td class="element" id="K"></td>
        <td class="element" id="Ca"></td></tr>
    <tr class="periods period5">
        <th>5</th>
    </tr>
    <tr class="periods period6">
        <th>6</th>
    </tr>
    <tr class="periods period7">
        <th>7</th>
    </tr>
  </tbody>
</table>
</code>```

Title: HTML colspan and rowspan not working

Body:
I have got a table 18 columns by 7 rows and i want to make td element to take 10 columns and 3 rows,so here is my code

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18

      1

        Protons

      2

      3

        4

        5

        6

        7

As you see bigInfo has an attribute of colspan equal to 10 and rowspan equal to 3,but unfortunately i only get cell 6 by 70 with a padding of 1 while i want that row to take a width of 10 columns and 3 rows.

Body:
Your code wasn't valid, you had some missing tags. Additional there is no <table> tag at all, don't know how your fully code is looking, but i updated it and it seems to work how it should!

<table>
  <thead>
    <tr>
      <td class="groups group1">1</td>
      <td class="groups group2">2</td>
      <td class="groups group3">3</td>
      <td class="groups group4">4</td>
      <td class="groups group5">5</td>
      <td class="groups group6">6</td>
      <td class="groups group7">7</td>
      <td class="groups group8">8</td>
      <td class="groups group9">9</td>
      <td class="groups group10">10</td>
      <td class="groups group11">11</td>
      <td class="groups group12">12</td>
      <td class="groups group13">13</td>
      <td class="groups group14">14</td>
      <td class="groups group15">15</td>
      <td class="groups group16">16</td>
      <td class="groups group17">17</td>
      <td class="groups group18">18</td>
    </tr>
  </thead>
  <tbody>
    <tr class="periods period1">
        <th>1</th>
        <td class="element" id="H"></td>
        <td class="basic_info">
            <span class="info_big"></span>
            <span class="info_spans">Protons</span>
        </td>
        <td class="biginfo" colspan="10" rowspan="3"></td>
        <td class="element" id="He"></td>
    </tr>
    <tr class="periods period2">
        <th>2</th>
        <td class="element" id="Li"></td>
        <td class="element" id="Be"></td>
    </tr>
    <tr class="periods period3">
        <th>3</th>
        <td class="element" id="Na"></td>
        <td class="element" id="Mg"></td>
        <td class="element" id="Al"></td>
        <td class="element" id="Si"></td>
    </tr>
    <tr class="periods period4">
        <th>4</th>
    <td class="element" id="K"></td>
        <td class="element" id="Ca"></td></tr>
    <tr class="periods period5">
        <th>5</th>
    </tr>
    <tr class="periods period6">
        <th>6</th>
    </tr>
    <tr class="periods period7">
        <th>7</th>
    </tr>
  </tbody>
</table>


问:
Including Javascript Files (not module) in Kotlin
I have two Javascript files. I have some Kotlin code that generates a Javascript file.  I also have a file (call it file.js) that depends on the generated javascript file from Kotlin.

Is there a way for me to include file.js in the Kotlin generated Javascript file using Gradle?  Is there a setting that can append resource Javascript files into the generated output?

My motivation is to slowly transition my Javascript project into Kotlin, and due to the structure of the project, I cannot create a module.  Just want to know if it is possible to do this and how.

答:
You can use Gradle's Ant integration for that. Here's an example from Gradle forums:

```<code>task concat(type: SourceTask) {
    source 'src'
    include '**/*.txt'
    outputs.file new File(buildDir, "full.txt")

    doLast {
        ant.concat(destfile: outputs.files.singleFile) {
            source.addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
        }
    }
}
</code>```

This will concatenate a bunch of files into a single full.txt file - adapt it to your specific case and have the task execute prior to assembling your final build artifact.

I have to say that for Javascript builds Gradle's integration with tools like Gulp and Grunt (via plugins) may be an even better match for you - those tools can naturally handle simple JS file concatenation, but they also offer many more tasks useful for working with web technologies.

Body:
You can use Gradle's Ant integration for that. Here's an example from Gradle forums:

task concat(type: SourceTask) {
    source 'src'
    include '**/*.txt'
    outputs.file new File(buildDir, "full.txt")

    doLast {
        ant.concat(destfile: outputs.files.singleFile) {
            source.addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
        }
    }
}

This will concatenate a bunch of files into a single full.txt file - adapt it to your specific case and have the task execute prior to assembling your final build artifact.

I have to say that for Javascript builds Gradle's integration with tools like Gulp and Grunt (via plugins) may be an even better match for you - those tools can naturally handle simple JS file concatenation, but they also offer many more tasks useful for working with web technologies.


问:
Taylor Series of ln(x) in Matlab
I am trying to compute the taylor series of ln(x) for any value of x.

What I have so far is:

```<code> clear
 clc
 n = input('Enter number of iiterations (n): ' );
 x = input('enter value of x (x): ');
 y = zeros(1,n);
 for i = 0:n
  y(i+1)=sum + (-1)^(n+1)*(x-1)^n/n;
end
</code>```

But this code seems to be broken and I can't figure out why. Any suggestions on how to improve?

答:
I suggest using built-in function and hopefully there is one. taylor(f,var) approximates f with the Taylor series expansion of f up to the fifth order at the point var = 0.

Specify Expansion Point :

Find the Taylor series expansions at x = 1 for these functions. The default expansion point is 0. To specify a different expansion point, use 'ExpansionPoint':

```<code>syms x
taylor(log(x), x, 'ExpansionPoint', 1)
ans =
x - (x - 1)^2/2 + (x - 1)^3/3 - (x - 1)^4/4 + (x - 1)^5/5 - 1
</code>```

Specify Truncation Order :

The default truncation order is 6.

```<code>syms x
f = log(x);
t6 = taylor(f, x);
</code>```

Use 'Order' to control the truncation order. For example, approximate the same expression up to the orders 8.

```<code>syms x
taylor(log(x), x, 'ExpansionPoint', 1, 'Order', 8);
</code>```

Title: Taylor Series of ln(x) in Matlab

Body:
I am trying to compute the taylor series of ln(x) for any value of x.

What I have so far is:

 clear
 clc
 n = input('Enter number of iiterations (n): ' );
 x = input('enter value of x (x): ');
 y = zeros(1,n);
 for i = 0:n
  y(i+1)=sum + (-1)^(n+1)*(x-1)^n/n;
end

But this code seems to be broken and I can't figure out why. Any suggestions on how to improve?

Body:
I suggest using built-in function and hopefully there is one. taylor(f,var) approximates f with the Taylor series expansion of f up to the fifth order at the point var = 0.

Specify Expansion Point :

Find the Taylor series expansions at x = 1 for these functions. The default expansion point is 0. To specify a different expansion point, use 'ExpansionPoint':

syms x
taylor(log(x), x, 'ExpansionPoint', 1)
ans =
x - (x - 1)^2/2 + (x - 1)^3/3 - (x - 1)^4/4 + (x - 1)^5/5 - 1

Specify Truncation Order :

The default truncation order is 6.

syms x
f = log(x);
t6 = taylor(f, x);

Use 'Order' to control the truncation order. For example, approximate the same expression up to the orders 8.

syms x
taylor(log(x), x, 'ExpansionPoint', 1, 'Order', 8);


问:
Iterating javascript object synchronously
I have an object like so:

```<code>let myObject = {
'db1': [db1_file1Id,db1_file2Id,db_1file3Id],
'db2': [db2_file1Id, db2_file2Id]
...
}
</code>```

I iterate through through this object and on each iteration: I connect to the database, retrieve the file, do some stuff and save the file back. Basically asynchronous stuff.

```<code>  for (let prop in myObject) {
    if (myObject.hasOwnProperty(prop)) {
      doStuff(prop, myObject[prop]);
    }
  }
</code>```

Now the doStuff function makes sure I have a local scope so there is no inconsistencies. But still, the execution is not synchronous due to the asynchronous operations inside each loop. I basically need one db to be completely processed before moving on to the next. How do I fix this?

One approach that I thought of was to have recursive loop. But as per my understanding, this would require me to change my data structure extensively which is sub-optimal imo.

```<code>let arr; //containing my data

process(x) {
 if (x < arr.length){
   //process(x+1) is called inside doStuff after asynchronous operations are complete
   doStuff(arr[x]);
 }
}
</code>```

答:
The following code might be close to what you are asking. I use indices i and j to loop through databases and files respectively :

var dbs = {
  db1: ["q", "w", "e", "r"],
  db2: ["t", "y"]
};

var names = Object.keys(dbs);
var db, x, i = 0, j = 0;

if (names.length > 0) {
  db = dbs[names[i]];
  x = db[j];
  console.log("start");
  asyncProcessing(x)
  .then(onSuccess)
  .catch(onFailure);
}

function onFailure (e) {
  console.log("[FAILURE]", e);
  console.log("end");
}

function onSuccess (xx) {
  console.log("[SUCCESS]", xx);
  j = (j + 1) % db.length; // next j
  if (j === 0) i = i + 1; // next i
  if (i < names.length) {
    db = dbs[names[i]];
    x = db[j];
    asyncProcessing(x)
    .then(onSuccess)
    .catch(onFailure);
  } else {
    console.log("end");
  }
}

function asyncProcessing (x) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      // force first two success then random
      if (x === "q" || x === "w" || Math.random() * 3 > 1) {
        resolve(x + x);
      } else {
        reject("Not lucky. Try again.");
      }
    }, 1000);
  });
}```

Body:
I have an object like so:

let myObject = {
'db1': [db1_file1Id,db1_file2Id,db_1file3Id],
'db2': [db2_file1Id, db2_file2Id]
...
}

I iterate through through this object and on each iteration: I connect to the database, retrieve the file, do some stuff and save the file back. Basically asynchronous stuff.

  for (let prop in myObject) {
    if (myObject.hasOwnProperty(prop)) {
      doStuff(prop, myObject[prop]);
    }
  }

Now the doStuff function makes sure I have a local scope so there is no inconsistencies. But still, the execution is not synchronous due to the asynchronous operations inside each loop. I basically need one db to be completely processed before moving on to the next. How do I fix this?

One approach that I thought of was to have recursive loop. But as per my understanding, this would require me to change my data structure extensively which is sub-optimal imo.

let arr; //containing my data

process(x) {
 if (x < arr.length){
   //process(x+1) is called inside doStuff after asynchronous operations are complete
   doStuff(arr[x]);
 }
}


问:
How to make a flex element fully expand to fill the containing element?
Here is my code.

I want the element .container to fully expand and occupy the area of .toplevel.

.toplevel {
  height: 100%;
  min-height: 800px;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  // min-height: 800px;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="up">
      This is down
    </div>
  </div>
</div></code>```

However it seems like the only way to make the .container larger height-wise is to define a min-height. It is too inflexible because I will have provide a different value for different device form factor.

How can I fix it?

答:
Make toplevel display:flex also with column direction and then add flex:1 to container :

I suppose you made a mistake in the code as you added two up divs so I corrected

.toplevel {
  height: 100%;
  min-height: 800px;
  border: solid 1px blue;
  display:flex;
  flex-direction:column;
}

.container {
  display: flex;
  border: solid 1px red;
  flex: 1;
  flex-direction: column;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="down">
      This is down
    </div>
  </div>
</div></code>```

Body:
Here is my code.

I want the element .container to fully expand and occupy the area of .toplevel.

.toplevel {
  height: 100%;
  min-height: 800px;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  // min-height: 800px;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}

      This is up

      This is down

However it seems like the only way to make the .container larger height-wise is to define a min-height. It is too inflexible because I will have provide a different value for different device form factor.

How can I fix it?

Body:
Make toplevel display:flex also with column direction and then add flex:1 to container :

I suppose you made a mistake in the code as you added two up divs so I corrected

.toplevel {
  height: 100%;
  min-height: 800px;
  border: solid 1px blue;
  display:flex;
  flex-direction:column;
}

.container {
  display: flex;
  border: solid 1px red;
  flex: 1;
  flex-direction: column;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}

<div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="down">
      This is down
    </div>
  </div>
</div>


问:
angular-uiroute error as $cookieStore.get is undefind
here im trying to fetch my Stored cookie value in $roortScope why im getting Error as .get of undefind  <code>$cookieStore.get('mycookie');</code>  </p>

```<code>angular.module('MyApp', ['ui.router', 'ui.bootstrap', 'ngCookies']).controller('HomeCtrl', function ($scope, $cookies, $state) {
 .run(function ($rootScope) {
        $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options, $scope,$cookieStore) {
            var Getcookies = $cookieStore.get('mycookie');

            if (toState.module == "Private" && !Getcookies.lenth=='undefind')
  {
            }
</code>```

答:
I think your problem is in your controller you have $cookies

```<code>.controller('HomeCtrl', function ($scope, $cookies, $state)
</code>```

but in your function you are using $cookieStore thats why your $cookieStore is undefined

```<code>function (event, toState, toParams, fromState, fromParams, options, $scope,$cookieStore)
</code>```

if you want to use $cookieStore you should change the $cookies in your controller with $cookieStore but keep in mind that $cookieStore is deprecated since version 1.4, you should use $cookies instead if you are using a newer version than 1.4.

Body:
here im trying to fetch my Stored cookie value in $roortScope why im getting Error as .get of undefind  $cookieStore.get('mycookie');

angular.module('MyApp', ['ui.router', 'ui.bootstrap', 'ngCookies']).controller('HomeCtrl', function ($scope, $cookies, $state) {
 .run(function ($rootScope) {
        $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options, $scope,$cookieStore) {
            var Getcookies = $cookieStore.get('mycookie');

            if (toState.module == "Private" && !Getcookies.lenth=='undefind')
  {
            }

Body:
I think your problem is in your controller you have $cookies

.controller('HomeCtrl', function ($scope, $cookies, $state)

but in your function you are using $cookieStore thats why your $cookieStore is undefined

function (event, toState, toParams, fromState, fromParams, options, $scope,$cookieStore)

if you want to use $cookieStore you should change the $cookies in your controller with $cookieStore but keep in mind that $cookieStore is deprecated since version 1.4, you should use $cookies instead if you are using a newer version than 1.4.


问:
IOS PhoneGap app rejected by App store becasue of cordova-plugin-geolocation
Apple App store has rejected my app & send this message We noticed that your app requests the user’s consent to access the location but does not clarify the use of this feature in the permission modal alert.

This app is developed using phonegap & we are accessing geolocation using a plugin named cordova-plugin-geolocation. They has also mentioned that apple can create problem & suggest to add following code

```<code><edit-config target="NSLocationWhenInUseUsageDescription" file="*Info.plist" mode="merge">
     <string>need location access to find things nearby</string>
</edit-config>
</code>```

I have added it like this & resubmit it again.

```<code><plugin name="cordova-plugin-geolocation" spec="2.4.2" />
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>need location access to find things nearby</string>
</edit-config>
</code>```

But they have sent same feedback. Now what should I do to fix this issue?

答: Check in xcode projec generated by cordova if the NSLocationWhenInUseUsageDescription key really exists in Info.plist. Sometimes it happened that cordova build did not copy plugins config correctly and I had to write them by hand.

Body:
Apple App store has rejected my app & send this message We noticed that your app requests the user’s consent to access the location but does not clarify the use of this feature in the permission modal alert.

This app is developed using phonegap & we are accessing geolocation using a plugin named cordova-plugin-geolocation. They has also mentioned that apple can create problem & suggest to add following code

<edit-config target="NSLocationWhenInUseUsageDescription" file="*Info.plist" mode="merge">
     <string>need location access to find things nearby</string>
</edit-config>

I have added it like this & resubmit it again.

<plugin name="cordova-plugin-geolocation" spec="2.4.2" />
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>need location access to find things nearby</string>
</edit-config>

But they have sent same feedback. Now what should I do to fix this issue?


问:
Difference between bytes.fromhex() and encode()
key = '140b41b22a29beb4061bda66b6747e14' # hex-encoded

```<code>>>> bytes.fromhex(key)
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'
</code>```

This seems to be correct as the code which I wrote for CBC (cipher) works after this.

The code below was inspired from this site.

```<code>>>> "".join([chr(int(key[i:i+2],16)) for i in range(0,len(key),2)]).encode()
b'\x14\x0bA\xc2\xb2*)\xc2\xbe\xc2\xb4\x06\x1b\xc3\x9af\xc2\xb6t~\x14'
</code>```

So, my question is: Why is the output different in both the cases and more importantly how come the length has increased from 16 bytes to 21 bytes in the 2nd case?

答:
You encoded the text representation of the hex values to UTF-8 (the default encoding if you don't specify one). For example, the B2 hex value is converted to a Unicode codepoint U+00B2, which encodes to UTF-8 as C2 B2.

You need to encode as Latin-1 if you want matching bytes for the Unicode codepoints:

```<code>>>> "".join([chr(int(key[i:i+2],16)) for i in range(0,len(key),2)]).encode('latin1')
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'
</code>```

The first 256 codepoints of Unicode correspond with the Latin-1 standard, so U+00B2 encodes directly to B2 in binary.

If you wanted to convert hex bytes to integers, do not create Unicode text. Just pass the integers directly to bytes:

```<code>>>> bytes(int(key[i:i + 2], 16) for i in range(0, len(key), 2))
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'
</code>```

That way you don't have to translate back from Unicode to bytes.

Body:
key = '140b41b22a29beb4061bda66b6747e14' # hex-encoded

>>> bytes.fromhex(key)
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'

This seems to be correct as the code which I wrote for CBC (cipher) works after this.

The code below was inspired from this site.

>>> "".join([chr(int(key[i:i+2],16)) for i in range(0,len(key),2)]).encode()
b'\x14\x0bA\xc2\xb2*)\xc2\xbe\xc2\xb4\x06\x1b\xc3\x9af\xc2\xb6t~\x14'

So, my question is: Why is the output different in both the cases and more importantly how come the length has increased from 16 bytes to 21 bytes in the 2nd case?

Body:
You encoded the text representation of the hex values to UTF-8 (the default encoding if you don't specify one). For example, the B2 hex value is converted to a Unicode codepoint U+00B2, which encodes to UTF-8 as C2 B2.

You need to encode as Latin-1 if you want matching bytes for the Unicode codepoints:

>>> "".join([chr(int(key[i:i+2],16)) for i in range(0,len(key),2)]).encode('latin1')
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'

The first 256 codepoints of Unicode correspond with the Latin-1 standard, so U+00B2 encodes directly to B2 in binary.

If you wanted to convert hex bytes to integers, do not create Unicode text. Just pass the integers directly to bytes:

>>> bytes(int(key[i:i + 2], 16) for i in range(0, len(key), 2))
b'\x14\x0bA\xb2*)\xbe\xb4\x06\x1b\xdaf\xb6t~\x14'

That way you don't have to translate back from Unicode to bytes.


问:
ModelVisual3D vs Model3DGroup
Is there any disadvantage of using ModelVisual3D over Model3DGroup. How much can the resource/performance impact possibly be?

ModelVisual3D gives me much more than Model3DGroup does but AFAIK everything that can be done with Model3DGroup can alos be done with ModelVisual3D.

So why not just always use ModelVisual3D?

答:
The answer is Yes. Having many ModelVisual3ds will be orders of magnitude slower than using a Model3DGroup

My understanding is that ModelVisual3D is more akin to a UIElement, i.e. more of a heavy weight object. MSDN says about ModelVisual3d:

"Provides services and properties that are common to all visual objects, including hit-testing, coordinate transformation, and bounding-box calculations."

So if you wanted to 100 clickable 3d objects in your scene you would need 100 ModelVisual3d elements.

Model3DGroup (along with GeometryModel3D) on the other hand is a Model3D  - the building blocks of 3d models. A single Model3D can appear as the content for several ModelVisual3Ds. Model3Ds are more lightweight than ModelVisual3D.

If you wanted to construct 3d models from building blocks (like Lego), you could define several GeometryModel3Ds, then combine them together using a Model3dGroup.

Yes, the class naming is horribly confusing, and I don't think the Daniel Lehenbauer sheds any light on the subject for the average human.

Title: ModelVisual3D vs Model3DGroup


问:
How to include Javascript and CSS files with Express.js
I have a simple node server running in a file called page.js just as a test of a system I am trying to setup.  In that file I have the following:

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

app.get('/', function(req, res) {
    res.sendFile('/Users/JohnFarkerson/Documents/SublimeFolder/index.html');
});

app.get('/*', function(req, res) {
    res.send("404 –– Page not found");
});

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

That path to the index file leads to the same directory (SublimeFolder) as the .js file is saved in.  Also in that directory are my javascript and css files. Within index.html, I have the following lines:

```<code><script language="javascript" type="text/javascript" src="myScript.js"></script>
<link rel="stylesheet" type="text/css" href="myStyleSheet.css">
</code>```

I have tried changing those paths within index.html to the full path on my computer, but that didn't solve my problem.  When I find the index.html file in Finder and double click, it opens file:///Users/JohnFarkerson/Documents/SublimeFolder/index.html in Chrome, which looks perfect.  However, when I run the server in node and then go to http://localhost:8080/, the page loads a very bare-bones version without any of my javascript or css.  What am I doing wrong here?

Edit:

It now works.  index.html looks like:

```<code>var express = require('express');
var app = express();
app.use('/js', express.static(__dirname + '/js'));
app.use('/css', express.static(__dirname + '/css'));

app.get('/', function(req, res) {
    res.sendFile('/Users/JohnFarkerson/Documents/SublimeFolder/index.html');
});

app.get('/*', function(req, res) {
    res.send("404 –– Page not found");
});

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

答:
First place javascript file in js folder then copy this code in app.js (main node.js file):</p>

```<code>app.use("/js", express.static(__dirname + '/js'));
</code>```

Body:
I have a simple node server running in a file called page.js just as a test of a system I am trying to setup.  In that file I have the following:

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

app.get('/', function(req, res) {
    res.sendFile('/Users/JohnFarkerson/Documents/SublimeFolder/index.html');
});

app.get('/*', function(req, res) {
    res.send("404 –– Page not found");
});

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

That path to the index file leads to the same directory (SublimeFolder) as the .js file is saved in.  Also in that directory are my javascript and css files. Within index.html, I have the following lines:

<link rel="stylesheet" type="text/css" href="myStyleSheet.css">

I have tried changing those paths within index.html to the full path on my computer, but that didn't solve my problem.  When I find the index.html file in Finder and double click, it opens file:///Users/JohnFarkerson/Documents/SublimeFolder/index.html in Chrome, which looks perfect.  However, when I run the server in node and then go to http://localhost:8080/, the page loads a very bare-bones version without any of my javascript or css.  What am I doing wrong here?

Edit:

It now works.  index.html looks like:

var express = require('express');
var app = express();
app.use('/js', express.static(__dirname + '/js'));
app.use('/css', express.static(__dirname + '/css'));

app.get('/', function(req, res) {
    res.sendFile('/Users/JohnFarkerson/Documents/SublimeFolder/index.html');
});

app.get('/*', function(req, res) {
    res.send("404 –– Page not found");
});

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

Body:
First place javascript file in js folder then copy this code in app.js (main node.js file):

app.use("/js", express.static(__dirname + '/js'));


问:
Method to go in which class?
I have 2 classes, player and game and a method called get_player_games($player_id). Which class does this method belong to?

I seem to run into this problem a bit, where I'm not 100% sure which class the method should go in. Is it just a matter of preference?

Thanks

答:
Assuming that a Game object models a single game, then the method clearly does not belong there as any given game would have no knowledge of other games.  It is conceivable that a Player object could keep a list of all games in which the player has participated.  But the way you have phrased the question suggests that we don't have a reference to a Player object but rather only a player ID.  Therefore, Player doesn't work either.

It sounds like that method would belong on a class named MatchHistory or Tournament or Ladder or something like that.

Title: Method to go in which class?


问:
Creating a .Net Standard library referencing ActionFilters, HTTPContext , HTTPException etc
I have a bunch of API's authored on .Netcore. I have some action attributes that I want to use across all the API's. I was planning to create a standard library project with the action filters and reference the same in all the API projects. However, I am not sure if I can add references to sytem.web. I am getting a bunch of errors about missing properties and am unable to find the HTTPConext and HTTPException types. What is the right way to create reusable actionfilter attributes for Web API's ?</p>

答:
There are two ways

1) If your library using only web apps you can add to library via nuget

Microsoft.AspNetCore.Mvc.Abstractions for filters

Microsoft.AspNetCore.Http.Abstractions for HttpContext

and creates shared filters and other manipulations with HttpContext in your library

2) Use DI. Creating some interface and use it in library and create implementation class of it in Projects. After that using DI to inject your class where this interface will called.

You can use it in Desktop\Web or whatever apps +

No libraries required +

You not depends on any version of you API +

For filters it's not worked -

You need implementation of your interface in each project -

example get cookie from HttpContext in your service in .Net Standard library

```<code>public interface ICookieAccessor
{
     string GetCookieValueByName(string name);
}

public class SomeServiceThatUsesCookie()
{
     private readonly ICookieAccessor _cookieAccessor;

     public SomeServiceThatUsesCookie(ICookieAccessor cookieAccessor){
           _cookieAccessor = cookieAccessor;
     }

     public string IWonnaCookie(string name){
           return _cookieAccessor.GetCookieValueByName(name);
     }
}
</code>```

and implement interface in Web Project (thats implementation should be in each projects)

```<code>public class CookieAccessor: ICookieAccessor
{
         private readonly IHttpContextAccessor _httpContext;

         public class CookieAccessor(IHttpContextAccessor httpContext){
                _httpContext = httpContext;
         }

         public string GetCookieValueByName(string name){
                if (_httpContext.HttpContext.Request.Cookies.TryGetValue(name,
                                                              out var value))
                {
                       return value;
                 }
                 return null;
         }
}
</code>```

and inject it in your WebApps startup file ConfigureServices method

```<code>services.AddTransient<ICookieAccessor, CookieAccessor>();
services.AddTransient<SomeServiceThatUsesCookie>();
</code>```

than in some controller use your service

```<code>public class SomeContoller: Controller
{
      private readonly SomeServiceThatUsesCookie _someService;

      public SomeContoller(SomeServiceThatUsesCookie someService){
             _someService = someService;
      }

      public string GetCookieValue(string name){
             return _someService.IWonnaCookie(name);
      }
}
</code>```

Body:
There are two ways

1) If your library using only web apps you can add to library via nuget

Microsoft.AspNetCore.Mvc.Abstractions for filters

Microsoft.AspNetCore.Http.Abstractions for HttpContext

and creates shared filters and other manipulations with HttpContext in your library

2) Use DI. Creating some interface and use it in library and create implementation class of it in Projects. After that using DI to inject your class where this interface will called.

You can use it in Desktop\Web or whatever apps +

No libraries required +

You not depends on any version of you API +

For filters it's not worked -

You need implementation of your interface in each project -

example get cookie from HttpContext in your service in .Net Standard library

public interface ICookieAccessor
{
     string GetCookieValueByName(string name);
}

public class SomeServiceThatUsesCookie()
{
     private readonly ICookieAccessor _cookieAccessor;

     public SomeServiceThatUsesCookie(ICookieAccessor cookieAccessor){
           _cookieAccessor = cookieAccessor;
     }

     public string IWonnaCookie(string name){
           return _cookieAccessor.GetCookieValueByName(name);
     }
}

and implement interface in Web Project (thats implementation should be in each projects)

public class CookieAccessor: ICookieAccessor
{
         private readonly IHttpContextAccessor _httpContext;

         public class CookieAccessor(IHttpContextAccessor httpContext){
                _httpContext = httpContext;
         }

         public string GetCookieValueByName(string name){
                if (_httpContext.HttpContext.Request.Cookies.TryGetValue(name,
                                                              out var value))
                {
                       return value;
                 }
                 return null;
         }
}

and inject it in your WebApps startup file ConfigureServices method

services.AddTransient<ICookieAccessor, CookieAccessor>();
services.AddTransient<SomeServiceThatUsesCookie>();

than in some controller use your service

public class SomeContoller: Controller
{
      private readonly SomeServiceThatUsesCookie _someService;

      public SomeContoller(SomeServiceThatUsesCookie someService){
             _someService = someService;
      }

      public string GetCookieValue(string name){
             return _someService.IWonnaCookie(name);
      }
}


问:
Alea GPU for loop cannot get field
I am just starting with ALEA and I am curious how you can access other types and references inside a given gpu parallel.for. when i do the following i get a runtime error that states "Cannot get field random. Possible reasons: 1) Static field is not supported.2) The field type is not supported. 3) In closure class, the field doesn't have [GpuParam] attribute."

This error makes sense but I am not sure what the correct implementation would be

```<code>    [GpuManaged]
    public void InitPoints()
    {
        var gp = Gpu.Default;
        gp.For(1, (10), (i) =>
        {
            int pointStart = random.Next(totalPoints) + 1;
            Pt point = new Pt(pointStart, ptAt[i]);
            point.Process();
        });
     }
</code>```

答: You try to call the System.Random.Next. This is .NET library code and cannot be compiled to GPU. There is no MSIL behind that function that could be accessed and compiled to run on the GPU. Also the System.Random.Next is a random number generator implemented for serial applications. You should use the parallel random number generators provided in cuRand, which are also exposed in Alea GPU. </p>

Title: Alea GPU for loop cannot get field

Body:
I am just starting with ALEA and I am curious how you can access other types and references inside a given gpu parallel.for. when i do the following i get a runtime error that states "Cannot get field random. Possible reasons: 1) Static field is not supported.2) The field type is not supported. 3) In closure class, the field doesn't have [GpuParam] attribute."

This error makes sense but I am not sure what the correct implementation would be

    [GpuManaged]
    public void InitPoints()
    {
        var gp = Gpu.Default;
        gp.For(1, (10), (i) =>
        {
            int pointStart = random.Next(totalPoints) + 1;
            Pt point = new Pt(pointStart, ptAt[i]);
            point.Process();
        });
     }


问:
How to run a matlab exe which contains python commands from another python code?
I have a Matlab code which calls some python modules. I made an exe from this Matlab code (let's call it pipeMe.exe) now I'm trying to run pipeMe.exe from another python code in another machine of course but apparently, it can't set the python version executable path from the second machine, thus it gives me this error:

Undefined variable "py" or class "py.sys.path".

Is there any way that I can set the pyversion executable from outside of Matlab while I run pipeMe.exe ? Or is there any possibility to set the pyversion executable path to a path that is accessible from both machines, and I just have to set it at the beginning of my pipeMe matlab code?

Thanks in advance for your help.

答:
Since your Matlab code has been compiled into executable (.exe), you can call it in Python using
    subprocess.Popen("pipeMe.exe")

If your exe file does not run, try to use deploytool of Matlab.

See also:

Calling an external command in Python

https://www.mathworks.com/matlabcentral/answers/4864-how-to-run-standalone-exe-file-on-computer-without-matlb


答:
To use percentage height, you need all parents to have a set height. In your case .toplevel parent body, doesn't have height, so .toplevel height of 100% doesn't work, and it causes the .container height to fail as well.
A simple solution is to set the .toplevel height using vh units instead of percentage:

.toplevel {
  height: 100vh;
  min-height: 800px;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  // min-height: 800px;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="up">
      This is down
    </div>
  </div>
</div></code>```

Title: How to make a flex element fully expand to fill the containing element?

Body:
To use percentage height, you need all parents to have a set height. In your case .toplevel parent body, doesn't have height, so .toplevel height of 100% doesn't work, and it causes the .container height to fail as well.
A simple solution is to set the .toplevel height using vh units instead of percentage:

.toplevel {
  height: 100vh;
  min-height: 800px;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  // min-height: 800px;
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}

<div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="up">
      This is down
    </div>
  </div>
</div>


答:
You can reverse the height and min-height of the .toplevel:

.toplevel {
  height: 800px;
  min-height: 100%;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  /*min-height: 800px;*/
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="up">
      This is down
    </div>
  </div>
</div></code>```

Body:
You can reverse the height and min-height of the .toplevel:

.toplevel {
  height: 800px;
  min-height: 100%;
  border: solid 1px blue;
}

.container {
  display: flex;
  border: solid 1px red;
  height: 100%;
  flex: 0 1 auto;
  flex-direction: column;
  /*min-height: 800px;*/
}

.up {
  display: flex;
  flex: 1 1 auto;
}

.down {
  display: flex;
  flex: 0 1 auto;
}

<div class="toplevel">
  <div class="container">
    <div class="up">
      This is up
    </div>
    <div class="up">
      This is down
    </div>
  </div>
</div>


问:
Build Project with Maven
I have build my project which i created in Netbeans with Maven.
I would like to open the built .jar - file but nothing happens.
I think that the problem is, that I have to specifiy the Main Class in the pom.xml file?

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>My_Project_name</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<build>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
      <groupId>org.apache.pdfbox</groupId>
      <artifactId>pdfbox</artifactId>
      <version>2.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.10.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.10.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>
</project>
</code>```

This is also what my main class looks like.

```<code>package com.myproject.My_Project_name;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;

public class App {
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OverviewScreen().setVisible(true);
            }
        });
    }
}
</code>```

Please help!

答:
You need to ensure that your dependencies are up to date and that you have everything you need to be working on your project.  The best way to troubleshoot this problem is to start a new maven project and start adding each dependency one by one until you find which dependency is the problem.

Here is the example pom.xml that should be working...For today.

pom.xml file:

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.myproject</groupId>
  <artifactId>My_Project_name</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>My_Project_name</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.10.1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
    </dependency>

    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.4</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>

  </dependencies>
</project>
</code>```

And so the main class will look like this:

```<code>package com.myproject.My_Project_name;
//import java.awt.Rectangle;
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.RandomAccessFile;

public class App {
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                //error in commented line below
                //new OverviewScreen().setVisible(true);
                System.out.println("hello");
            }
        });
    }
}
</code>```

So it looks like you are encountering your issue when you are using the following code:

```<code>    new OverviewScreen().setVisible(true);
</code>```

Then before exporting the project to a .jar, make sure you select the main  class of the application entry point.  In my case the wizard for exporting to .jar has it on the final page of the wizard and you must click next until you see it.  For this example, select App.java (not AppTest.java) as your main.

Specifying the main entry point for the program can also be done other ways.  If you want to ensure it's working, check to see if the program is manifested within command prompt:

```<code>C:\Users\Me\Documents>java -jar myProjectName.jar
</code>```

Once the project has been exported as a .jar, attempt to execute it on the command prompt.

```<code>C:\Users\Me\Documents>java -cp myProjectName.jar com.myproject.My_Project_name.App
</code>```

If your dependencies are working, and you exported the .jar with the main file selected properly you should result with the command line outputting:

```<code>hello
</code>```

from running the .jar.  Also make sure you are entering the command when you are in the containing folder of the .jar file.

Title: Build Project with Maven

Body:
I have build my project which i created in Netbeans with Maven.
I would like to open the built .jar - file but nothing happens.
I think that the problem is, that I have to specifiy the Main Class in the pom.xml file?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>My_Project_name</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<build>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
      <groupId>org.apache.pdfbox</groupId>
      <artifactId>pdfbox</artifactId>
      <version>2.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.10.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.10.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>
</project>

This is also what my main class looks like.

package com.myproject.My_Project_name;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;

public class App {
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OverviewScreen().setVisible(true);
            }
        });
    }
}

Please help!

Body:
You need to ensure that your dependencies are up to date and that you have everything you need to be working on your project.  The best way to troubleshoot this problem is to start a new maven project and start adding each dependency one by one until you find which dependency is the problem.

Here is the example pom.xml that should be working...For today.

pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.myproject</groupId>
  <artifactId>My_Project_name</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>My_Project_name</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.10.1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
    </dependency>

    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.4</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>

  </dependencies>
</project>

And so the main class will look like this:

package com.myproject.My_Project_name;
//import java.awt.Rectangle;
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.RandomAccessFile;

public class App {
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                //error in commented line below
                //new OverviewScreen().setVisible(true);
                System.out.println("hello");
            }
        });
    }
}

So it looks like you are encountering your issue when you are using the following code:

    new OverviewScreen().setVisible(true);

Then before exporting the project to a .jar, make sure you select the main  class of the application entry point.  In my case the wizard for exporting to .jar has it on the final page of the wizard and you must click next until you see it.  For this example, select App.java (not AppTest.java) as your main.

Specifying the main entry point for the program can also be done other ways.  If you want to ensure it's working, check to see if the program is manifested within command prompt:

C:\Users\Me\Documents>java -jar myProjectName.jar

Once the project has been exported as a .jar, attempt to execute it on the command prompt.

C:\Users\Me\Documents>java -cp myProjectName.jar com.myproject.My_Project_name.App

If your dependencies are working, and you exported the .jar with the main file selected properly you should result with the command line outputting:

hello

from running the .jar.  Also make sure you are entering the command when you are in the containing folder of the .jar file.


问:
How to reuse views (pages) in ASP.NET Core MVC?
Before ASP.NET Core MVC, we would use RazorGenerator to compile views into assemblies, and we would reuse those views in another project, by introducing a custom ViewEngine that would load the view from the assembly instead of file-system.

In ASP.NET Core MVC there is this concept of pre-compiled views and it works out of the box for version 2.0 and creates an assembly that by convention has the name of project_name.PrecompiledViews.dll.

I have two problems though that I can't find an answer for on Google.
First I don't know how to reuse that DLL in another project. Like if I have About.cshtml page in CompanyBase.dll, how can I reuse that page/view in ProjectAlpha?

And also I don't want view compilation to happen on publish. How can I change it to happen on build?

答:
There is a Application Parts concept in ASP.NET Core:

An Application Part is an abstraction over the resources of an application, from which MVC features like controllers, view components, or tag helpers may be discovered.

Add the following into .csproj (for your library with views) to include views as embedded resources into the dll:

```<code><ItemGroup>
   <EmbeddedResource Include="Views\**\*.cshtml" />
</ItemGroup>
</code>```

then add assembly as app part and register the ViewComponentFeatureProvider for View discovery:

```<code>// using System.Reflection;
// using Microsoft.AspNetCore.Mvc.ApplicationParts;
// using Microsoft.AspNetCore.Mvc.ViewComponents;

public void ConfigureServices(IServiceCollection services)
{
     ...
     var assembly = typeof(ClassInYourLibrary).GetTypeInfo().Assembly;
     var part = new AssemblyPart(assembly);

     services.AddMvc()
             .ConfigureApplicationPartManager(p => {
                p.ApplicationParts.Add(part);
                p.FeatureProviders.Add(new ViewComponentFeatureProvider());
             });
}
</code>```

Another way is to use the EmbeddedFileProvider. This approach is described in this SO answer.

Body:
There is a Application Parts concept in ASP.NET Core:

An Application Part is an abstraction over the resources of an application, from which MVC features like controllers, view components, or tag helpers may be discovered.

Add the following into .csproj (for your library with views) to include views as embedded resources into the dll:

<ItemGroup>
   <EmbeddedResource Include="Views\**\*.cshtml" />
</ItemGroup>

then add assembly as app part and register the ViewComponentFeatureProvider for View discovery:

// using System.Reflection;
// using Microsoft.AspNetCore.Mvc.ApplicationParts;
// using Microsoft.AspNetCore.Mvc.ViewComponents;

public void ConfigureServices(IServiceCollection services)
{
     ...
     var assembly = typeof(ClassInYourLibrary).GetTypeInfo().Assembly;
     var part = new AssemblyPart(assembly);

     services.AddMvc()
             .ConfigureApplicationPartManager(p => {
                p.ApplicationParts.Add(part);
                p.FeatureProviders.Add(new ViewComponentFeatureProvider());
             });
}

Another way is to use the EmbeddedFileProvider. This approach is described in this SO answer.


问:
How to reference bootstrap colors as a variable in css?
I'm trying to customize my bootstrap theme a bit.  I'd like to do something like this in my own css file:

```<code>div {
background-color: @brand-warning;//or @body-bg or @dark-gray, etc
}
</code>```

That is, Bootstrap has a warning color variable, but I'd like to access it.
Anyway to do this?

Thanks

答:
Version bootstrap@4.0.0-beta.2 comes with many SASS maps as in

```<code>$grays: () !default;

$grays: map-merge((
    "100": $gray-100,
    "200": $gray-200,
    "300": $gray-300,
    "400": $gray-400,
    "500": $gray-500,
    "600": $gray-600,
    "700": $gray-700,
    "800": $gray-800,
    "900": $gray-900
), $grays);
</code>```

For those who don't know how to use a SASS map please use

```<code>body {
    padding-top: 5rem;
    background: map-get($grays, "200")
}
</code>```

And you will have access a nice range of standardised colours.

Ah! Please don't forget to import the _variables file as in

```<code>@import "~bootstrap/scss/_variables.scss";
</code>```

:)

Body:
I'm trying to customize my bootstrap theme a bit.  I'd like to do something like this in my own css file:

div {
background-color: @brand-warning;//or @body-bg or @dark-gray, etc
}

That is, Bootstrap has a warning color variable, but I'd like to access it.
Anyway to do this?

Thanks

Body:
Version bootstrap@4.0.0-beta.2 comes with many SASS maps as in

$grays: () !default;

$grays: map-merge((
    "100": $gray-100,
    "200": $gray-200,
    "300": $gray-300,
    "400": $gray-400,
    "500": $gray-500,
    "600": $gray-600,
    "700": $gray-700,
    "800": $gray-800,
    "900": $gray-900
), $grays);

For those who don't know how to use a SASS map please use

body {
    padding-top: 5rem;
    background: map-get($grays, "200")
}

And you will have access a nice range of standardised colours.

Ah! Please don't forget to import the _variables file as in

@import "~bootstrap/scss/_variables.scss";

:)


问:
set /p not taking environment variables
I am trying to match a batch script to do this tutorial automatically, for any system.

```<code>@echo off
for /f "tokens=4* delims= " %%A in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures"') do (set loc=%%A %%B)
set loc=%loc%\Spotlight
set /p loc=Location for images (default - "%loc%") [use %%loc%% for default]?:
start robocopy "%localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets" "%temp%\spotlight"
ren %temp%\spotlight\*.* *.jpg
robocopy "%temp%\spotlight" "%loc%"
start %SystemRoot%\explorer.exe %loc%
</code>```

However, if I try typing %loc%\Spotlight2, it places it in the Desktop\%loc%\spotlight2 (desktop is the current working directory).

Is there a way to make set /p take environment variables?

答:
There's a way to do what you want without default locations! It involves variable manipulation:

```<code>...
setlocal enabledelayedexpansion
set loc=%loc%\Spotlight
set default=%loc%
set /p "loc=Location [%loc%] for default: "
set out=!loc:%%loc%%=%default%!
echo %out%
...
</code>```

Hence, typing %loc% replaces it with the original value of loc.

I tested this by typing %loc%\s and it performed as expected. In terms of it being the correct directory, thats to do with how you set the value of loc prior to this code.

Title: set /p not taking environment variables

Body:
I am trying to match a batch script to do this tutorial automatically, for any system.

@echo off
for /f "tokens=4* delims= " %%A in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures"') do (set loc=%%A %%B)
set loc=%loc%\Spotlight
set /p loc=Location for images (default - "%loc%") [use %%loc%% for default]?:
start robocopy "%localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets" "%temp%\spotlight"
ren %temp%\spotlight\*.* *.jpg
robocopy "%temp%\spotlight" "%loc%"
start %SystemRoot%\explorer.exe %loc%

However, if I try typing %loc%\Spotlight2, it places it in the Desktop\%loc%\spotlight2 (desktop is the current working directory).

Is there a way to make set /p take environment variables?

Body:
There's a way to do what you want without default locations! It involves variable manipulation:

...
setlocal enabledelayedexpansion
set loc=%loc%\Spotlight
set default=%loc%
set /p "loc=Location [%loc%] for default: "
set out=!loc:%%loc%%=%default%!
echo %out%
...

Hence, typing %loc% replaces it with the original value of loc.

I tested this by typing %loc%\s and it performed as expected. In terms of it being the correct directory, thats to do with how you set the value of loc prior to this code.


问:
Adding an array of seconds to a reference datetime
How do I add an array of seconds to a reference datetime in python e.g:

```<code>ref_time = datetime.datetime(year=2017, month=6, day=5, hour=10, minute=30, second=30)

secs = (0,1,2,3,4,5,6,7,8,9,10)
</code>```

The result needs to be something:

2017,6,5,10,30,30

2017,6,5,10,30,31

2017,6,5,10,30,32

2017,6,5,10,30,33
   etc etc

I have tried this but its not working, what am I doing wrong?

```<code>d = datetime.timedelta(seconds=np.int(secs))
new_timestamp = timestamp+d
</code>```

Sorry for the simple question, i'm quite new to python

答:
timedelta accepts one argument as the second, that means you need to pass the seconds within the secs tuple one at a time. You can achieve this simply using a list comprehension:

```<code>In [1]: import datetime

In [2]: ref_time = datetime.datetime(year=2017, month=6, day=5, hour=10, minute=30, second=30)

In [3]: secs = (0,1,2,3,4,5,6,7,8,9,10)

In [4]: [ref_time + datetime.timedelta(seconds=i) for i in secs]
Out[4]:
[datetime.datetime(2017, 6, 5, 10, 30, 30),
 datetime.datetime(2017, 6, 5, 10, 30, 31),
 datetime.datetime(2017, 6, 5, 10, 30, 32),
 datetime.datetime(2017, 6, 5, 10, 30, 33),
 datetime.datetime(2017, 6, 5, 10, 30, 34),
 datetime.datetime(2017, 6, 5, 10, 30, 35),
 datetime.datetime(2017, 6, 5, 10, 30, 36),
 datetime.datetime(2017, 6, 5, 10, 30, 37),
 datetime.datetime(2017, 6, 5, 10, 30, 38),
 datetime.datetime(2017, 6, 5, 10, 30, 39),
 datetime.datetime(2017, 6, 5, 10, 30, 40)]
</code>```

Body:
How do I add an array of seconds to a reference datetime in python e.g:

ref_time = datetime.datetime(year=2017, month=6, day=5, hour=10, minute=30, second=30)

secs = (0,1,2,3,4,5,6,7,8,9,10)

The result needs to be something:

2017,6,5,10,30,30

2017,6,5,10,30,31

2017,6,5,10,30,32

2017,6,5,10,30,33
   etc etc

I have tried this but its not working, what am I doing wrong?

d = datetime.timedelta(seconds=np.int(secs))
new_timestamp = timestamp+d

Sorry for the simple question, i'm quite new to python

Body:
timedelta accepts one argument as the second, that means you need to pass the seconds within the secs tuple one at a time. You can achieve this simply using a list comprehension:

In [1]: import datetime

In [2]: ref_time = datetime.datetime(year=2017, month=6, day=5, hour=10, minute=30, second=30)

In [3]: secs = (0,1,2,3,4,5,6,7,8,9,10)

In [4]: [ref_time + datetime.timedelta(seconds=i) for i in secs]
Out[4]:
[datetime.datetime(2017, 6, 5, 10, 30, 30),
 datetime.datetime(2017, 6, 5, 10, 30, 31),
 datetime.datetime(2017, 6, 5, 10, 30, 32),
 datetime.datetime(2017, 6, 5, 10, 30, 33),
 datetime.datetime(2017, 6, 5, 10, 30, 34),
 datetime.datetime(2017, 6, 5, 10, 30, 35),
 datetime.datetime(2017, 6, 5, 10, 30, 36),
 datetime.datetime(2017, 6, 5, 10, 30, 37),
 datetime.datetime(2017, 6, 5, 10, 30, 38),
 datetime.datetime(2017, 6, 5, 10, 30, 39),
 datetime.datetime(2017, 6, 5, 10, 30, 40)]


问:
How to remove/change the border when clicking inside an input field in Bootstrap 4?
I used this but it didn't work.</p>

```<code>input[type="email"],
input[type="password"],
textarea,
select {
    outline: none;
}
</code>```

答:
These styles disable the blue color:

If you use forms with all fields having the form-control class (the Bootstrap way), we can overwrite these things for the focus event:

form .form-control:focus{
  border-color: #ced4da;
  box-shadow: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<form>
  <div class="form-group">
    <label for="exampleFormControlInput1">Email address</label>
    <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect1">Example select</label>
    <select class="form-control" id="exampleFormControlSelect1">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect2">Example multiple select</label>
    <select multiple class="form-control" id="exampleFormControlSelect2">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlTextarea1">Example textarea</label>
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
  </div>
</form></code>```

ContentLicense: CC BY-SA 4.0

Body:
I used this but it didn't work.

input[type="email"],
input[type="password"],
textarea,
select {
    outline: none;
}

Body:
These styles disable the blue color:

If you use forms with all fields having the form-control class (the Bootstrap way), we can overwrite these things for the focus event:

form .form-control:focus{
  border-color: #ced4da;
  box-shadow: none;
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<form>
  <div class="form-group">
    <label for="exampleFormControlInput1">Email address</label>
    <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect1">Example select</label>
    <select class="form-control" id="exampleFormControlSelect1">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect2">Example multiple select</label>
    <select multiple class="form-control" id="exampleFormControlSelect2">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlTextarea1">Example textarea</label>
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
  </div>
</form>


问:
Stop and deallocate an Azure VM within the guest OS
The VM info:

Basic A1 Serie VM with Ubuntu 16 on it

How to shutdown (or Stop) and de-allocate the VM in Azure without having to go to the azure portal?

Bearing in mind in Azure if you execute shutdown -h 0; it will stop the VM but won't deallocate it.

I'm asking this because I don't have a direct connection to the Azure portal nor do I have logins to it. I want to deallocate the VM using the guest OS only.

答:
You can use any means of automation, Powershell\CLI\different SDK to shutdown the vm. you can créate a script and to just execute it.
Example for Azure Powershell.

Stop-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"


问:
Subtracts values one list from another in javascript
How to remove all values from var a = [1,2,2,2,3] which are present in var b=[2]If a values is present in b variable all of its occurrences must be remove

```<code> var a = [1,2,2,2,5];
 var b = [2];
 const result = a.filter(function(el){

  return /// which condition .?

 });
</code>```

How to remove the b var value. and we have many logics please answer it briefly

答:
A simple solution is to use Array#filter, and check if the value exists using Array#indexOf:

var a = [1, 2, 2, 2, 5];
var b = [2];

var result = a.filter(function(n) {
  return b.indexOf(n) === -1;
});

console.log(result);```
</div>
</div>
</p>

<p>However, this requires redundant iterations of the 2nd array. A better solution is to create a dictionary object from <code>b</code> using Array#reduce, and use it in the filtering:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var a = [1, 2, 2, 2, 5];
var b = [2];
var bDict = b.reduce(function(d, n) {
  d[n] = true;

  return d;
}, Object.create(null));

var result = a.filter(function(n) {
  return !bDict[n];
});

console.log(result);</code>```

Body:
How to remove all values from var a = [1,2,2,2,3] which are present in var b=[2]If a values is present in b variable all of its occurrences must be remove

 var a = [1,2,2,2,5];
 var b = [2];
 const result = a.filter(function(el){

  return /// which condition .?

 });

How to remove the b var value. and we have many logics please answer it briefly

Body:
A simple solution is to use Array#filter, and check if the value exists using Array#indexOf:

var a = [1, 2, 2, 2, 5];
var b = [2];

var result = a.filter(function(n) {
  return b.indexOf(n) === -1;
});

console.log(result);

However, this requires redundant iterations of the 2nd array. A better solution is to create a dictionary object from b using Array#reduce, and use it in the filtering:

var a = [1, 2, 2, 2, 5];
var b = [2];
var bDict = b.reduce(function(d, n) {
  d[n] = true;

  return d;
}, Object.create(null));

var result = a.filter(function(n) {
  return !bDict[n];
});

console.log(result);