问:
Radio buttons are scrolling with background, how to fix this?
I've got a problem with the radio buttons.
I am trying to fix the radio buttons on the background just like the other elements.
But now they are scrolling with the background when I am making the page smaller.
Can you please help me?
Thanks in advance!
For example:

label[class=number]::before {
    counter-increment: section;
    content: counter(section) " " ;
    display: inline-block;
    color: white;
    width: 20px;
    background-color: black;
    text-align: center;
    padding-top: 1%;
    margin-left: 10px;
    padding-bottom: 1%;
}

label[class=number] {
 display: inline-block;
    margin-top: 20px;
    width: 345px;
}

#bestellen input[type=number], #bestellen input[type=text], select {
 width: 40px;
    margin-left: 102%;
    display: block;
    margin-top: -7%;
    border-color: skyblue;
    border-style: double;
}

input[type=range] {
    width: 40px;
    position: relative;
    margin-left: 102%;
    background-color: transparent;
    margin-top: -5%;
    display: block;
}

small {
 display: block;
    margin-left: 420px;
    margin-top: -1.5%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form id="bestellen" action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
        <label class="number" id="David_Vann">David Vann - Aquarium: <input size="3" name="David_Vann" type="number" min="1"></label><small> Max. 10 exemplaren</small>
        <label class="number" id="Robert_Seethaler">Robert Seethaler - Een heel leven: <input size="3" name="Robert_Seethaler" type="text" pattern="[0-9]{2}"></label><small> Max. 99 exemplaren</small>
        <label id="Paula" class="number">Paula Hawkins - Het meisje in de trein: <input name="Paula_Hawkins" type="range" min="0" max="15" step="5" list="Paula_Hawkins"></label><small>Bestel 0, 5, 10 of 15 exemplaren</small>
          <datalist id="Paula_Hawkins">
            <option value="0">
            <option value="5">
            <option value="10">
            <option value="15">
         </datalist>
        <label class="number" id="Ernest_van_der_kwast">Ernest van der Kwast - De ijsmakers: </label>
        <label id="ernest"> <input type="radio" name="Ernest van der kwast" value="1">1</label>
        <label id="ernest"> <input type="radio" name="Ernest van der kwast" value="10">10</label>
        <label id="ernest"> <input type="radio" name="Ernest van der kwast" value="20">20</label><br>
        <label class="number" id="Bert_natter">Bert Natter - Remington:
            <select name="Bert Natter">
              <option value="geen">geen</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
             </select>
         </label>
   </form> </code>```

答:
label[class=number]::before {
    counter-increment: section;
    content: counter(section) " " ;
    display: inline-block;
    color: white;
    width: 20px;
    background-color: black;
    text-align: center;
    padding-top: 1%;
    margin-left: 10px;
    padding-bottom: 1%;
}

label[class=number] {
 display: inline-block;
    margin-top: 20px;
    width: 345px;
}

#bestellen input[type=number], #bestellen input[type=text], select {
 width: 40px;
    margin-left: 102%;
    display: block;
    margin-top: -7%;
    border-color: skyblue;
    border-style: double;
}

input[type=range] {
    width: 40px;
    position: relative;
    margin-left: 102%;
    background-color: transparent;
    margin-top: -5%;
    display: block;
}

small {
 display: block;
    margin-left: 420px;
    margin-top: -1.5%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form id="bestellen" action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
        <label class="number" id="David_Vann">David Vann - Aquarium: <input size="3" name="David_Vann" type="number" min="1"></label><small> Max. 10 exemplaren</small>
        <label class="number" id="Robert_Seethaler">Robert Seethaler - Een heel leven: <input size="3" name="Robert_Seethaler" type="text" pattern="[0-9]{2}"></label><small> Max. 99 exemplaren</small>

        <label id="Paula" class="number">Paula Hawkins - Het meisje in de trein: <input name="Paula_Hawkins" type="range" min="0" max="15" step="5" list="Paula_Hawkins"></label><small>Bestel 0, 5, 10 of 15 exemplaren</small>
          <datalist id="Paula_Hawkins">
            <option value="0">
            <option value="5">
            <option value="10">
            <option value="15">
         </datalist>
         <br>

        <label class="number" id="Ernest_van_der_kwast">Ernest van der Kwast - De ijsmakers: </label>

        1<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="1"></label>
        10<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="10"></label>
        20<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="20"></label><br>

        <label class="number" id="Bert_natter">Bert Natter - Remington:
            <select name="Bert Natter">
              <option value="geen">geen</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
             </select>
         </label>
   </form></code>```

Body:
I've got a problem with the radio buttons.
I am trying to fix the radio buttons on the background just like the other elements.
But now they are scrolling with the background when I am making the page smaller.
Can you please help me?
Thanks in advance!
For example:

label[class=number]::before {
    counter-increment: section;
    content: counter(section) " " ;
    display: inline-block;
    color: white;
    width: 20px;
    background-color: black;
    text-align: center;
    padding-top: 1%;
    margin-left: 10px;
    padding-bottom: 1%;
}

label[class=number] {
 display: inline-block;
    margin-top: 20px;
    width: 345px;
}

#bestellen input[type=number], #bestellen input[type=text], select {
 width: 40px;
    margin-left: 102%;
    display: block;
    margin-top: -7%;
    border-color: skyblue;
    border-style: double;
}

input[type=range] {
    width: 40px;
    position: relative;
    margin-left: 102%;
    background-color: transparent;
    margin-top: -5%;
    display: block;
}

small {
 display: block;
    margin-left: 420px;
    margin-top: -1.5%;
}

<form id="bestellen" action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
        David Vann - Aquarium: <input size="3" name="David_Vann" type="number" min="1"> Max. 10 exemplaren
        Robert Seethaler - Een heel leven: <input size="3" name="Robert_Seethaler" type="text" pattern="[0-9]{2}"> Max. 99 exemplaren
        Paula Hawkins - Het meisje in de trein: <input name="Paula_Hawkins" type="range" min="0" max="15" step="5" list="Paula_Hawkins">Bestel 0, 5, 10 of 15 exemplaren
          <datalist id="Paula_Hawkins">
            <option value="0">
            <option value="5">
            <option value="10">
            <option value="15">
         </datalist>
        Ernest van der Kwast - De ijsmakers:
         <input type="radio" name="Ernest van der kwast" value="1">1
         <input type="radio" name="Ernest van der kwast" value="10">10
         <input type="radio" name="Ernest van der kwast" value="20">20

        Bert Natter - Remington:
            <select name="Bert Natter">
              <option value="geen">geen</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
             </select>

   </form>

Body:
label[class=number]::before {
    counter-increment: section;
    content: counter(section) " " ;
    display: inline-block;
    color: white;
    width: 20px;
    background-color: black;
    text-align: center;
    padding-top: 1%;
    margin-left: 10px;
    padding-bottom: 1%;
}

label[class=number] {
 display: inline-block;
    margin-top: 20px;
    width: 345px;
}

#bestellen input[type=number], #bestellen input[type=text], select {
 width: 40px;
    margin-left: 102%;
    display: block;
    margin-top: -7%;
    border-color: skyblue;
    border-style: double;
}

input[type=range] {
    width: 40px;
    position: relative;
    margin-left: 102%;
    background-color: transparent;
    margin-top: -5%;
    display: block;
}

small {
 display: block;
    margin-left: 420px;
    margin-top: -1.5%;
}

<form id="bestellen" action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
        <label class="number" id="David_Vann">David Vann - Aquarium: <input size="3" name="David_Vann" type="number" min="1"></label><small> Max. 10 exemplaren</small>
        <label class="number" id="Robert_Seethaler">Robert Seethaler - Een heel leven: <input size="3" name="Robert_Seethaler" type="text" pattern="[0-9]{2}"></label><small> Max. 99 exemplaren</small>

        <label id="Paula" class="number">Paula Hawkins - Het meisje in de trein: <input name="Paula_Hawkins" type="range" min="0" max="15" step="5" list="Paula_Hawkins"></label><small>Bestel 0, 5, 10 of 15 exemplaren</small>
          <datalist id="Paula_Hawkins">
            <option value="0">
            <option value="5">
            <option value="10">
            <option value="15">
         </datalist>
         <br>

        <label class="number" id="Ernest_van_der_kwast">Ernest van der Kwast - De ijsmakers: </label>

        1<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="1"></label>
        10<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="10"></label>
        20<label id="ernest"> <input type="radio" name="Ernest van der kwast" value="20"></label><br>

        <label class="number" id="Bert_natter">Bert Natter - Remington:
            <select name="Bert Natter">
              <option value="geen">geen</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
             </select>
         </label>
   </form>


来源: stackexchange

问:
How to compare an object's color property | Three.js
I know how to set the value of an object's color property, but I'm failing in checking the same.
I need to compare the color of an object's mesh so that I can manipulate it if the condition is true.

Basic code:

```<code>object.traverse( function( child ) {
    if ( child instanceof THREE.Mesh ) {
        child.castShadow = true;
        child.material.color.set(0x00ff00);
        if ( child.material.color == '0x00ff00' )   {  //this comparison check
            child.material.color.set(0x0000ff);
        }
    }
} );
</code>```

Is this comparison correct, or is there another way to check this property's value?

答:
You can compare colors using a pattern like so:

```<code>var color = new THREE.Color( 0xff0000 ); // create once and reuse if needed

console.log( material.color.equals( color ); );
</code>```

three.js .r85

ContentLicense: CC BY-SA 3.0

Body:
I know how to set the value of an object's color property, but I'm failing in checking the same.
I need to compare the color of an object's mesh so that I can manipulate it if the condition is true.

Basic code:

object.traverse( function( child ) {
    if ( child instanceof THREE.Mesh ) {
        child.castShadow = true;
        child.material.color.set(0x00ff00);
        if ( child.material.color == '0x00ff00' )   {  //this comparison check
            child.material.color.set(0x0000ff);
        }
    }
} );

Is this comparison correct, or is there another way to check this property's value?

Body:
You can compare colors using a pattern like so:

var color = new THREE.Color( 0xff0000 ); // create once and reuse if needed

console.log( material.color.equals( color ); );

three.js .r85


问:
Where does dotPeek store it's cache?
I was using dotPeek and my connection dropped right when it was going online to get some code for a given class. So my router has supplied it with 500 gateway page and now whenever I try to look at the code for that class I instead get an  html view of that router page i.e. its been cached.

The problem is there doesn't seem to be any way to clear it. I've deleted everything in AppData for JetBrains for both roaming and local but to no effect.

Where is the disassembly cache for dotPeek?

答:
In the latest version (2017.1.2), it appears to be in:

C:\Users{username}\AppData\Local\Temp\DecompilationTemp

Title: Where does dotPeek store it's cache?


问:
StreamWriter not writing to an existing file
I am trying to write some text to the file using StreamWriter and getting the
path for the file from FolderDialog selected folder. My code works fine if the
file does not already exist. but if the file already exist it throws the Exception
that the file is in used by other process.

```<code>using(StreamWriter sw = new StreamWriter(FolderDialog.SelectedPath + @"\my_file.txt")
{
    sw.writeLine("blablabla");
}
</code>```

Now if I write like this:

```<code>using(StreamWriter sw = new StreamWriter(@"C:\some_folder\my_file.txt")
</code>```

it works fine with an existing file.

答:
Try this

```<code> using (StreamWriter sw = File.AppendText(@"C:\some_folder\my_file.txt"))
    {
          sw.writeLine("blablabla");
    }
</code>```

it will only work in existing file, so to validate if the file is new or already exists, do something like

```<code> string path = @"C:\some_folder\my_file.txt";
        if (!File.Exists(path))
        {
            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(path))
            {
                //once file was created insert the text or the columns
                sw.WriteLine("blbalbala");

            }
        }
        // if already exists just write
using (StreamWriter sw = File.AppendText(@"C:\some_folder\my_file.txt"))
    {
          sw.writeLine("blablabla");
    }
</code>```

OwnerDisplayName: Muzzammil

ContentLicense: CC BY-SA 2.5

Body:
I am trying to write some text to the file using StreamWriter and getting the
path for the file from FolderDialog selected folder. My code works fine if the
file does not already exist. but if the file already exist it throws the Exception
that the file is in used by other process.

using(StreamWriter sw = new StreamWriter(FolderDialog.SelectedPath + @"\my_file.txt")
{
    sw.writeLine("blablabla");
}

Now if I write like this:

using(StreamWriter sw = new StreamWriter(@"C:\some_folder\my_file.txt")

it works fine with an existing file.

Body:
Try this

 using (StreamWriter sw = File.AppendText(@"C:\some_folder\my_file.txt"))
    {
          sw.writeLine("blablabla");
    }

it will only work in existing file, so to validate if the file is new or already exists, do something like

 string path = @"C:\some_folder\my_file.txt";
        if (!File.Exists(path))
        {
            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(path))
            {
                //once file was created insert the text or the columns
                sw.WriteLine("blbalbala");

            }
        }
        // if already exists just write
using (StreamWriter sw = File.AppendText(@"C:\some_folder\my_file.txt"))
    {
          sw.writeLine("blablabla");
    }


问:
Declaring Method with generic type
I was using generic types in C# and I am new to using generic types. So, right now I am stuck with a problem. I have some classes like these:

```<code>public class MyModel1
{
}

public class MyModel2
{
}

public class BaseClass<T>
{
}

public class ChildClass1 : BaseClass<MyModel1>
{
}

public class ChildClass2 : BaseClass<MyModel2>
{
}

public class AnotherClass
{
    //What will be the syntax of declaring this method
    //The syntax of the following method is wrong and incomplete.
    //It's there just to give an idea about whai i want to do.
    public void MyMethod<T>()
      where T : BaseClass<..what to write..>
    {

    }
}
</code>```

My question is what will be the correct syntax of declaring MyMethod if I want to call MyMethod like this:

```<code>MyMethod<ChildClass1>();
</code>```

答:
You've forgotten to mention the return type and adding <T> after the class name. For example, if the return type is void, you could declare the method as:

```<code>        public void MyMethod<T>()
      where T : BaseClass<T>
{

}
</code>```

Title: Declaring Method with generic type

Body:
I was using generic types in C# and I am new to using generic types. So, right now I am stuck with a problem. I have some classes like these:

public class MyModel1
{
}

public class MyModel2
{
}

public class BaseClass<T>
{
}

public class ChildClass1 : BaseClass<MyModel1>
{
}

public class ChildClass2 : BaseClass<MyModel2>
{
}

public class AnotherClass
{
    //What will be the syntax of declaring this method
    //The syntax of the following method is wrong and incomplete.
    //It's there just to give an idea about whai i want to do.
    public void MyMethod<T>()
      where T : BaseClass<..what to write..>
    {

    }
}

My question is what will be the correct syntax of declaring MyMethod if I want to call MyMethod like this:

MyMethod<ChildClass1>();

Body:
You've forgotten to mention the return type and adding <T> after the class name. For example, if the return type is void, you could declare the method as:

        public void MyMethod<T>()
      where T : BaseClass<T>
{

}


问:
Decoding an mpf exif block in an MPO stereo image file
I am writing something to get at the information contained in an MPO multi-picture file produced by cameras such as the fuji 3D cameras.

I have the proposed spec, which is obviously written to confuse, and is available from here:
CIPA multi picture spec PDF and have navigated the normal exif parts and extracted the MFP information.

Section 5.2.3 which describes the header lists
The header lists:

```<code>4 byte endian flag
4 byte offset
-- start of MP Index --
2 byte count
12 byte version
12 byte number of images
12 byte MP entry
12 byte Individual unique ID list
12 byte total number of capture frames
4 byte offset to next IFD.
</code>```

The diagram shows the MP Entry and Unique ID list pointing to a offset (which would make 12 bytes).
However, in the description that follows it shows that the MP entry should be 16 bytes for every image (which in my sample image with two images, it is), and the individual unique ID being 33 bytes for every image (my sample doesn't have this).

Up to the number of images, everything is as it should be. I have 2 images, the version is correct, and there appear to be 3 blocks (count).
However, the third block (which is the MP Entry) has the right code, the correct number of bytes and the correct type, but contains the following information

```<code>32 00 00 00  52 00 00 00  02 00 02 20  40 63  1B 00
00 00 00 00  00 00 00 00  02 00 02 00  EE 6F  1B 00
</code>```

The text says the contents of this should be

```<code>offset   length   name
0x00     4        Individual Image attribute
0x04     4        individual Image Size
0x08     4        Individual image offset
0x10     2        dependant image 1 entry number
0x12     2        dependant image 2 entry number
</code>```

Clearly that makes no sense that if there are two images (they are effectively 10MP jpegs) that they have a size of 52 bytes and 0.

Could anyone take a look at this and check I am not going mad in my interpretation of it, or does anyone know what should be here?

Sorry, I know it is a bit complicated but I really cannot see where this is going wrong.

答:
I believe your tag is ok.

Chapter 5.2 (MP Extensions) of the spec states MP index IFD as following:

Count (2 bytes)

MP Index Fields (Overall structure Info)

Offset of Next IFD (4 bytes)

Value (MP Index IFD)

Up to the number of images, everything is fine, as per spec. Starting from the MP Entry tag the bytes should be parsed as following:
(I'll be using data parsed from my MPO file)

```<code>02 b0 07 00   20 00 00 00   32 00 00 00   52 00 00 00
02 00 02 20   00 13 18 00   00 00 00 00   00 00 00 00
</code>```

02-b0     - Tag ID (MP entry), 2 bytes

07-00     - Type (7 = undefined), 2
bytes

20-00-00-00 - 32 (16 x NumberOfImages,
two images in my file, this value was
parsed before), 4 bytes

32-00-00-00 - Offset of First IFD (50
bytes, starting from endianness tag),
4 bytes

That's where MP entry data ends. It's weird that there are no Individual Image Unique ID List (b003) or Total Number of Captured Frames (b004) tags, maybe they aren't necessary. Anyway, the next 4 bytes show offset of the next IFD, i.e.:

52-00-00-00 - Offset of Next IFD (82
bytes, starting from endiannesss
tag), 4 bytes

First IFD (in my case) starts immediately after the offset of Next IFD:

02-00-02-20 - Individual Image attr., 4
bytes

00-13-18-00 - Individual image size
(which states for 1 577 728 bytes of
data in my case), 4 bytes

00-00-00-00 - Individual image data
offset (states for 0 in case of first
image), 4 bytes

00-00 - Dependent image 1 (no
dependent image), 2 bytes

00-00 - Dependent image 2 (no
dependent image), 2 bytes

In your case, the data should be parsed as following:

```<code>32 00 00 00  52 00 00 00  02 00 02 20  40 63  1B 00
00 00 00 00  00 00 00 00  02 00 02 00  EE 6F  1B 00
</code>```

32-00-00-00 - Offset of First IFD (50
bytes, starting from endianness tag),
4 bytes

52-00-00-00 - Offset of Next IFD (82
bytes, starting from endiannesss
tag), 4 bytes

02-00-02-20 - Individual Image attr., 4
bytes

00-13-18-00 - Individual image size
(which states for 1 794 880 bytes of
data), 4 bytes

00-00-00-00 - Individual image data
offset (states for 0 in case of first
image), 4 bytes

00-00 - Dependent image 1 (no
dependent image), 2 bytes

00-00 - Dependent image 2 (no
dependent image), 2 bytes

And starting next image's data:

02-00-02-00 - Individual Image attr., 4
bytes

EE-6F-1B-00 - Individual image size
(which states for 1 798 126 bytes of
data), 4 bytes
etc.

ABOUT IMAGE SIZE AND OFFSETS

Image size and offsets can confuse a bit. Spec says that:

"Image size is the data between SOI
  and EOI markers" (ch. 5.2.3.3.2)

and

"Data offset (for the second image) is
  specified relative to the address of
  the MP Endian field in the MP Header"
  (ch. 5.2.3.3.3)

Which I understand to be as following:

```<code>SOI---MPF_FIELDS-------------EOI
      ^
      MP endian field
      XXXXXXXXXXXXXXXXXXXXXXXXXXSOI--------------------------EOI
</code>```

(first image, say, 2164288 bytes between SOI and EOI markers, including the markers. Second image, 2221368 bytes between SOI and EOI markers, including the markers. XXXXX states for offset)

Offset of the second image means that SOI marker is starting in lengthOf(XXXXX) bytes after MP endian marker, which is in the first image's MP field.
I suspect that if you subtract offset value from first image size, you should get MP Endian marker position.

Body:
I am writing something to get at the information contained in an MPO multi-picture file produced by cameras such as the fuji 3D cameras.

I have the proposed spec, which is obviously written to confuse, and is available from here:
CIPA multi picture spec PDF and have navigated the normal exif parts and extracted the MFP information.

Section 5.2.3 which describes the header lists
The header lists:

4 byte endian flag
4 byte offset
-- start of MP Index --
2 byte count
12 byte version
12 byte number of images
12 byte MP entry
12 byte Individual unique ID list
12 byte total number of capture frames
4 byte offset to next IFD.

The diagram shows the MP Entry and Unique ID list pointing to a offset (which would make 12 bytes).
However, in the description that follows it shows that the MP entry should be 16 bytes for every image (which in my sample image with two images, it is), and the individual unique ID being 33 bytes for every image (my sample doesn't have this).

Up to the number of images, everything is as it should be. I have 2 images, the version is correct, and there appear to be 3 blocks (count).
However, the third block (which is the MP Entry) has the right code, the correct number of bytes and the correct type, but contains the following information

32 00 00 00  52 00 00 00  02 00 02 20  40 63  1B 00
00 00 00 00  00 00 00 00  02 00 02 00  EE 6F  1B 00

The text says the contents of this should be

offset   length   name
0x00     4        Individual Image attribute
0x04     4        individual Image Size
0x08     4        Individual image offset
0x10     2        dependant image 1 entry number
0x12     2        dependant image 2 entry number

Clearly that makes no sense that if there are two images (they are effectively 10MP jpegs) that they have a size of 52 bytes and 0.

Could anyone take a look at this and check I am not going mad in my interpretation of it, or does anyone know what should be here?

Sorry, I know it is a bit complicated but I really cannot see where this is going wrong.

Body:
I believe your tag is ok.

Chapter 5.2 (MP Extensions) of the spec states MP index IFD as following:

Count (2 bytes)

MP Index Fields (Overall structure Info)

Offset of Next IFD (4 bytes)

Value (MP Index IFD)

Up to the number of images, everything is fine, as per spec. Starting from the MP Entry tag the bytes should be parsed as following:
(I'll be using data parsed from my MPO file)

02 b0 07 00   20 00 00 00   32 00 00 00   52 00 00 00
02 00 02 20   00 13 18 00   00 00 00 00   00 00 00 00

02-b0     - Tag ID (MP entry), 2 bytes

07-00     - Type (7 = undefined), 2
bytes

20-00-00-00 - 32 (16 x NumberOfImages,
two images in my file, this value was
parsed before), 4 bytes

32-00-00-00 - Offset of First IFD (50
bytes, starting from endianness tag),
4 bytes

That's where MP entry data ends. It's weird that there are no Individual Image Unique ID List (b003) or Total Number of Captured Frames (b004) tags, maybe they aren't necessary. Anyway, the next 4 bytes show offset of the next IFD, i.e.:

52-00-00-00 - Offset of Next IFD (82
bytes, starting from endiannesss
tag), 4 bytes

First IFD (in my case) starts immediately after the offset of Next IFD:

02-00-02-20 - Individual Image attr., 4
bytes

00-13-18-00 - Individual image size
(which states for 1 577 728 bytes of
data in my case), 4 bytes

00-00-00-00 - Individual image data
offset (states for 0 in case of first
image), 4 bytes

00-00 - Dependent image 1 (no
dependent image), 2 bytes

00-00 - Dependent image 2 (no
dependent image), 2 bytes

In your case, the data should be parsed as following:

32 00 00 00  52 00 00 00  02 00 02 20  40 63  1B 00
00 00 00 00  00 00 00 00  02 00 02 00  EE 6F  1B 00

32-00-00-00 - Offset of First IFD (50
bytes, starting from endianness tag),
4 bytes

52-00-00-00 - Offset of Next IFD (82
bytes, starting from endiannesss
tag), 4 bytes

02-00-02-20 - Individual Image attr., 4
bytes

00-13-18-00 - Individual image size
(which states for 1 794 880 bytes of
data), 4 bytes

00-00-00-00 - Individual image data
offset (states for 0 in case of first
image), 4 bytes

00-00 - Dependent image 1 (no
dependent image), 2 bytes

00-00 - Dependent image 2 (no
dependent image), 2 bytes

And starting next image's data:

02-00-02-00 - Individual Image attr., 4
bytes

EE-6F-1B-00 - Individual image size
(which states for 1 798 126 bytes of
data), 4 bytes
etc.

ABOUT IMAGE SIZE AND OFFSETS

Image size and offsets can confuse a bit. Spec says that:

"Image size is the data between SOI
  and EOI markers" (ch. 5.2.3.3.2)

and

"Data offset (for the second image) is
  specified relative to the address of
  the MP Endian field in the MP Header"
  (ch. 5.2.3.3.3)

Which I understand to be as following:

SOI---MPF_FIELDS-------------EOI
      ^
      MP endian field
      XXXXXXXXXXXXXXXXXXXXXXXXXXSOI--------------------------EOI

(first image, say, 2164288 bytes between SOI and EOI markers, including the markers. Second image, 2221368 bytes between SOI and EOI markers, including the markers. XXXXX states for offset)

Offset of the second image means that SOI marker is starting in lengthOf(XXXXX) bytes after MP endian marker, which is in the first image's MP field.
I suspect that if you subtract offset value from first image size, you should get MP Endian marker position.


问:
How to pass by reference to another object's method in VC++ (error C2664)
After using lovely C# for years, my C++ skills suffered a lot, but I'm confident to get back on track with your great help.
Passing a value by reference to a method WITHIN a class works:

```<code>// WORKS
class Foo {
  void FooAdd(int i, int j, int &k) {
    k = i + j;
  }
  void FooDo() {
    int i = 20;
    FooAdd(1, 2, i);
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
}

int main() {
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}
</code>```

If this method is moved to another class, VC++ cannot compile the file anymore:

```<code>// error C2664: "void Bar::BarAdd(int,int,int *)" : Konvertierung von Argument 3 von "int" in "int *" nicht möglich
// error C2664: "void Bar::BarAdd(int,int,int *)" : cannot convert parameter 3 from 'int' to 'int *'
class Bar {
  void BarAdd(int i, int j, int &k) {
    k = i + j;
  }
}

class Foo {
  void FooDo() {
    int i = 20;
    Bar* bar = new Bar();
    bar->BardAdd(1, 2, i);    // error C2664
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
}

int main() { // unchanged
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}
</code>```

答:
If you correct the typo, add the missing semi-colons, include iostream, and make the methods public, it will work. See https://ideone.com/lWDpbl</p>

```<code>#include <iostream>

class Bar {
public:
  void BarAdd(int i, int j, int &k) {
    k = i + j;
  }
};

class Foo {
public:
  void FooDo() {
    int i = 20;
    Bar* bar = new Bar();
    bar->BarAdd(1, 2, i);    // error C2664
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
};

int main() { // unchanged
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}
</code>```

Body:
After using lovely C# for years, my C++ skills suffered a lot, but I'm confident to get back on track with your great help.
Passing a value by reference to a method WITHIN a class works:

// WORKS
class Foo {
  void FooAdd(int i, int j, int &k) {
    k = i + j;
  }
  void FooDo() {
    int i = 20;
    FooAdd(1, 2, i);
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
}

int main() {
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}

If this method is moved to another class, VC++ cannot compile the file anymore:

// error C2664: "void Bar::BarAdd(int,int,int *)" : Konvertierung von Argument 3 von "int" in "int *" nicht möglich
// error C2664: "void Bar::BarAdd(int,int,int *)" : cannot convert parameter 3 from 'int' to 'int *'
class Bar {
  void BarAdd(int i, int j, int &k) {
    k = i + j;
  }
}

class Foo {
  void FooDo() {
    int i = 20;
    Bar* bar = new Bar();
    bar->BardAdd(1, 2, i);    // error C2664
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
}

int main() { // unchanged
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}

Body:
If you correct the typo, add the missing semi-colons, include iostream, and make the methods public, it will work. See https://ideone.com/lWDpbl

#include <iostream>

class Bar {
public:
  void BarAdd(int i, int j, int &k) {
    k = i + j;
  }
};

class Foo {
public:
  void FooDo() {
    int i = 20;
    Bar* bar = new Bar();
    bar->BarAdd(1, 2, i);    // error C2664
    std::string s = std::to_string(i) + " (3: SUCCESS; 20: ERROR)";
    std::cout << s;
  }
};

int main() { // unchanged
  Foo* foo = new Foo();
  foo->FooDo();
  return 0;
}


问:
Parsing incoming mail with Google App Engine?
We have our mail setup with Google Apps. We want to be able to run some regular expressions on incoming mail and process this information.

Is this possible today with Google App Engine? Does Google provide some kind of infrastructure that can do this?

答:
As another option to the answer from Gabriel I would recommend to use go environment of App Engine on Sending and Receiving Mail with the Mail API.

From The Documentation:

Receiving Mail

Your app can receive email at addresses of the following form:

```<code>anything@appid.appspotmail.com
</code>```

Compare to a configuration on handling incoming mail in python as discussed here, enabling incoming mail in your app's app.yaml file is fairly simple:

```<code>inbound_services:
- mail
</code>```

Name your app file as mail.go, then register a handler to the /_ah/mail/ path and read the email's data from the *http.Requestlike using net/mail like this:

```<code>func incomingMail(w http.ResponseWriter, r *http.Request) {
        ctx := appengine.NewContext(r)
        defer r.Body.Close()
        var b bytes.Buffer
        if _, err := b.ReadFrom(r.Body); err != nil {
                log.Errorf(ctx, "Error reading body: %v", err)
                return
        }
        log.Infof(ctx, "Received mail: %v", b)
}
</code>```

Sending Mail

Follow this guideline to register your sender emails as authorized senders

Use the mail.Message type to set the sender, recipient, subject, and body of the message.

Send the email with the mail.Send function.

```<code>func confirm(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    addr := r.FormValue("email")
    url := createConfirmationURL(r)
    msg := &mail.Message{
        Sender:  "Example.com Support <support@example.com>",
        To:      []string{addr},
        Subject: "Confirm your registration",
        Body:    fmt.Sprintf(confirmMessage, url),
    }
    if err := mail.Send(ctx, msg); err != nil {
        log.Errorf(ctx, "Couldn't send email: %v", err)
    }
}
</code>```

Deploy

The complete sample code of both Receiving and Sending is available here on GitHub:

GoogleCloudPlatform/golang-samples/docs/appengine/mail/mail.go

To clone the sample code, go to your Console. Click the button to open Cloud Shell:

then similar with this quickstart enter the steps below:

```<code>$ SOURCEDIR=https://github.com/GoogleCloudPlatform/golang-samples.git
$ TUTORIALDIR=~/src/your-application-id/go_gae_samples
$ git clone $SOURCEDIR $TUTORIALDIR
$ cd $TUTORIALDIR
$ git checkout master
$ cat docs/appengine/mail/app.yaml
$ cat docs/appengine/mail/mail.go
$ goapp serve docs/appengine/mail/app.yaml
</code>```

From here you can access the app on port 8080 by using Web preview.

To terminate press Ctrl+C in the Cloud Shell.

Finally you may deploy your app

```<code>goapp deploy -application your-application-id -version 0
</code>```

Click the URL to visit it

```<code>http://your-application-id.appspot.com/
</code>```

Then send an email to anything@your-application-id.appspotmail.com see if it works.

OwnerDisplayName: Ken

LastEditorDisplayName: Richard Levasseur

ContentLicense: CC BY-SA 4.0

Body:
As another option to the answer from Gabriel I would recommend to use go environment of App Engine on Sending and Receiving Mail with the Mail API.

From The Documentation:

Receiving Mail

Your app can receive email at addresses of the following form:

anything@appid.appspotmail.com

Compare to a configuration on handling incoming mail in python as discussed here, enabling incoming mail in your app's app.yaml file is fairly simple:

inbound_services:
- mail

Name your app file as mail.go, then register a handler to the /_ah/mail/ path and read the email's data from the *http.Requestlike using net/mail like this:

func incomingMail(w http.ResponseWriter, r *http.Request) {
        ctx := appengine.NewContext(r)
        defer r.Body.Close()
        var b bytes.Buffer
        if _, err := b.ReadFrom(r.Body); err != nil {
                log.Errorf(ctx, "Error reading body: %v", err)
                return
        }
        log.Infof(ctx, "Received mail: %v", b)
}

Sending Mail

Follow this guideline to register your sender emails as authorized senders

Use the mail.Message type to set the sender, recipient, subject, and body of the message.

Send the email with the mail.Send function.

func confirm(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    addr := r.FormValue("email")
    url := createConfirmationURL(r)
    msg := &mail.Message{
        Sender:  "Example.com Support <support@example.com>",
        To:      []string{addr},
        Subject: "Confirm your registration",
        Body:    fmt.Sprintf(confirmMessage, url),
    }
    if err := mail.Send(ctx, msg); err != nil {
        log.Errorf(ctx, "Couldn't send email: %v", err)
    }
}

Deploy

The complete sample code of both Receiving and Sending is available here on GitHub:

GoogleCloudPlatform/golang-samples/docs/appengine/mail/mail.go

To clone the sample code, go to your Console. Click the button to open Cloud Shell:

then similar with this quickstart enter the steps below:

$ SOURCEDIR=https://github.com/GoogleCloudPlatform/golang-samples.git
$ TUTORIALDIR=~/src/your-application-id/go_gae_samples
$ git clone $SOURCEDIR $TUTORIALDIR
$ cd $TUTORIALDIR
$ git checkout master
$ cat docs/appengine/mail/app.yaml
$ cat docs/appengine/mail/mail.go
$ goapp serve docs/appengine/mail/app.yaml

From here you can access the app on port 8080 by using Web preview.

To terminate press Ctrl+C in the Cloud Shell.

Finally you may deploy your app

goapp deploy -application your-application-id -version 0

Click the URL to visit it

http://your-application-id.appspot.com/

Then send an email to anything@your-application-id.appspotmail.com see if it works.


问:
How to show formatted text using javascript?
I have some values that I have written in php. The var here is derived from nl2br $ther. The code is written so that it removes certain words from the here array, but I do not want to remove some values such as

```<code>  "<br/>"
</code>```

and \n to preserve the formatting.
I tried the following code (and a combination of others but it is not working)

```<code><script = "javascript">
var r = <?php echo json_encode($t, JSON_HEX_TAG); ?>; // getting random nu.
 var here = <?php echo json_encode($ther, JSON_HEX_TAG); ?>;
 var jtotal = <?php echo json_encode($total, JSON_HEX_TAG); ?>;

var count =0;
for(var b=0; b < jtotal; b++)  {

if ((b==r) && (here[b] = "<br")) {
   document.write("<br");
}
else if ((b==r) && (here[b] = "/>")) {
 document.write("/>");
}
else if ((b==r) && (here[b] = "\n")) {
 document.write("\n");
}

 else if (b==r){
count = count+1;
document.write("____(" + count+ ")____");
r=r+2;
}

else {

    document.write(here[b] + " ");
}

</script>
</code>```

答:
```<code>for(var b=0; b < jtotal; b++)  {

if ((b==r) && (here[b] = "<br")) {
   document.write("<br");
}
else if ((b==r) && (here[b] = "/>")) {
 document.write("/>");
}
else if ((b==r) && (here[b] = "\n")) {
 document.write("\n");
}
</code>```

to this

```<code>for(var b=0; b < jtotal; b++)  {

if ((b==r) && (here[b] == "<br")) {
   document.write("<br");
}
else if ((b==r) && (here[b] == "/>")) {
 document.write("/>");
}
else if ((b==r) && (here[b] == "\n")) {
 document.write("\n");
}
</code>```

the issue: you're not using a comparison operator, rather an assignment operator.

Body:
I have some values that I have written in php. The var here is derived from nl2br $ther. The code is written so that it removes certain words from the here array, but I do not want to remove some values such as

  "
"

and \n to preserve the formatting.
I tried the following code (and a combination of others but it is not working)

Body:
for(var b=0; b < jtotal; b++)  {

if ((b==r) && (here[b] = "<br")) {
   document.write("<br");
}
else if ((b==r) && (here[b] = "/>")) {
 document.write("/>");
}
else if ((b==r) && (here[b] = "\n")) {
 document.write("\n");
}

to this

for(var b=0; b < jtotal; b++)  {

if ((b==r) && (here[b] == "<br")) {
   document.write("<br");
}
else if ((b==r) && (here[b] == "/>")) {
 document.write("/>");
}
else if ((b==r) && (here[b] == "\n")) {
 document.write("\n");
}

the issue: you're not using a comparison operator, rather an assignment operator.


问:
How do I create a public default constructor and an overloaded constructor?
I am extremely new to Java and coding in general. I am working on a project where I have created two interfaces and am now creating a concrete class named VehicleChassis that implements my Chassis interface. First, I created a String named chassisName instance variable. Now, I need to create a default constructor and overloaded constructor with the following value - A String with a parameter value of chassisName. I have searched the Internet on how to do both, but I am so confused. Help!

Below is the code I have so far.

```<code>public abstract class VehicleChassis implements Chassis{
public String chassisName;
}
</code>```

答:
You can create constructor as below.If the instance variable is more and all are not mandatory then you can use builder pattern to build your object step by step.  </p>

```<code> public class VehicleChassis implements Chassis {
        public String chassisName;

        public VehicleChassis() {
            // some code
        }

        public VehicleChassis(String chassisName) {
            this.chassisName = chassisName;
        }

    }
</code>```

Body:
I am extremely new to Java and coding in general. I am working on a project where I have created two interfaces and am now creating a concrete class named VehicleChassis that implements my Chassis interface. First, I created a String named chassisName instance variable. Now, I need to create a default constructor and overloaded constructor with the following value - A String with a parameter value of chassisName. I have searched the Internet on how to do both, but I am so confused. Help!

Below is the code I have so far.

public abstract class VehicleChassis implements Chassis{
public String chassisName;
}

Body:
You can create constructor as below.If the instance variable is more and all are not mandatory then you can use builder pattern to build your object step by step.

 public class VehicleChassis implements Chassis {
        public String chassisName;

        public VehicleChassis() {
            // some code
        }

        public VehicleChassis(String chassisName) {
            this.chassisName = chassisName;
        }

    }


问:
How to wait for Function to finish before continuing
In my current project I want to be able to display the users current position on a map.
I have implemented this functionality via the requestLocation method provided by Apple, but the problem is that my code continues without waiting for the requestLocation Function to finish.

The flow is this: First I call the positionController.setPositionViaLocationData() function, which handles the setup and execution of the requestLocation method. In the end this receives the coordinates and stores them in the userPosition member of the PositionController.
In the next line of code I want to access the userPosition via the PositionController but here comes my problem:

The line ...

```<code>var userPosition = positionController.getPosition()
</code>```

... is executed before positionController.setPositionViaLocationData() is finished, thus it takes the default values stored in userPosition.

How can I make my code wait for positionController.setPositionViaLocationData() before executing
var userPosition = positionController.getPosition()?
I already read stuff about Closures and CompletionManagers but I don't get that stuff to work for me.

Heres the code of both classes, first the ViewController who calls the functions:

```<code>import UIKit
import GoogleMaps
import CoreLocation

class MapViewController: UIViewController, CLLocationManagerDelegate {

    let positionController = PositionController()

    override func viewDidLoad() {
        super.viewDidLoad()

        positionController.setPositionViaLocationData()
        var userPosition = positionController.getPosition()
        setUserPositionMarkerOnMapAndShowMap(userPositionLatitude: userPosition.userLatitude, userPositionLongitude: userPosition.userLongitude)

    }

    func setUserPositionMarkerOnMapAndShowMap(userPositionLatitude: Double, userPositionLongitude: Double){
        let camera = GMSCameraPosition.camera(withLatitude: userPositionLatitude,
                                              longitude: userPositionLongitude, zoom:3)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera:camera)
        let marker = GMSMarker()

        self.view = mapView
        marker.snippet = "Munich"
        marker.appearAnimation = GMSMarkerAnimation.pop
        marker.map = mapView

        self.view = mapView
    }

}
</code>```

And now my PositionController class:

```<code>import Foundation
import CoreLocation

class PositionController: CLLocationManager, CLLocationManagerDelegate {

    let locationManager: CLLocationManager
    var userPosition = Position(longitude: 0,latitude: 0)

    override init() {
        self.locationManager = CLLocationManager()
        print("---------------Init---------------------------")
    }

    func setPositionViaLocationData(){

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
        locationManager.requestLocation()
    }

    func setPosition(longitude: Double, latitude: Double){
        userPosition.longitude = longitude
        userPosition.latitude = latitude
    }

    func getPosition() -> (userLongitude: Double, userLatitude: Double){
        return (userPosition.longitude, userPosition.latitude)
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error)
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
        userPosition.latitude = locValue.latitude
        userPosition.longitude = locValue.longitude
    }
}
</code>```

答:
I know of two methods to access location information once CLLocationManager.requestLocation() has a value.

Call your functions in the delegate methods of your location manager.

```<code>func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    //call function when you get user location
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    //handle error
}
</code>```

Use PromiseKit, which provides a Promise that only returns once the location manager updates. You have to have CLLocationManager.promise() to get a Promise that returns when the location manager updates its location.

If you plan to use a lot of asynchronous calls, I would go for PromiseKit, since it makes handling and running asynchronous functions sequentially really straightforward. However, getting to know how PromiseKit works takes some time so if you would only use it for this single use case, I would rather go for method 1.

Body:
In my current project I want to be able to display the users current position on a map.
I have implemented this functionality via the requestLocation method provided by Apple, but the problem is that my code continues without waiting for the requestLocation Function to finish.

The flow is this: First I call the positionController.setPositionViaLocationData() function, which handles the setup and execution of the requestLocation method. In the end this receives the coordinates and stores them in the userPosition member of the PositionController.
In the next line of code I want to access the userPosition via the PositionController but here comes my problem:

The line ...

var userPosition = positionController.getPosition()

... is executed before positionController.setPositionViaLocationData() is finished, thus it takes the default values stored in userPosition.

How can I make my code wait for positionController.setPositionViaLocationData() before executing
var userPosition = positionController.getPosition()?
I already read stuff about Closures and CompletionManagers but I don't get that stuff to work for me.

Heres the code of both classes, first the ViewController who calls the functions:

import UIKit
import GoogleMaps
import CoreLocation

class MapViewController: UIViewController, CLLocationManagerDelegate {

    let positionController = PositionController()

    override func viewDidLoad() {
        super.viewDidLoad()

        positionController.setPositionViaLocationData()
        var userPosition = positionController.getPosition()
        setUserPositionMarkerOnMapAndShowMap(userPositionLatitude: userPosition.userLatitude, userPositionLongitude: userPosition.userLongitude)

    }

    func setUserPositionMarkerOnMapAndShowMap(userPositionLatitude: Double, userPositionLongitude: Double){
        let camera = GMSCameraPosition.camera(withLatitude: userPositionLatitude,
                                              longitude: userPositionLongitude, zoom:3)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera:camera)
        let marker = GMSMarker()

        self.view = mapView
        marker.snippet = "Munich"
        marker.appearAnimation = GMSMarkerAnimation.pop
        marker.map = mapView

        self.view = mapView
    }

}

And now my PositionController class:

import Foundation
import CoreLocation

class PositionController: CLLocationManager, CLLocationManagerDelegate {

    let locationManager: CLLocationManager
    var userPosition = Position(longitude: 0,latitude: 0)

    override init() {
        self.locationManager = CLLocationManager()
        print("---------------Init---------------------------")
    }

    func setPositionViaLocationData(){

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
        locationManager.requestLocation()
    }

    func setPosition(longitude: Double, latitude: Double){
        userPosition.longitude = longitude
        userPosition.latitude = latitude
    }

    func getPosition() -> (userLongitude: Double, userLatitude: Double){
        return (userPosition.longitude, userPosition.latitude)
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error)
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
        userPosition.latitude = locValue.latitude
        userPosition.longitude = locValue.longitude
    }
}

Body:
I know of two methods to access location information once CLLocationManager.requestLocation() has a value.

Call your functions in the delegate methods of your location manager.

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    //call function when you get user location
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    //handle error
}

Use PromiseKit, which provides a Promise that only returns once the location manager updates. You have to have CLLocationManager.promise() to get a Promise that returns when the location manager updates its location.

If you plan to use a lot of asynchronous calls, I would go for PromiseKit, since it makes handling and running asynchronous functions sequentially really straightforward. However, getting to know how PromiseKit works takes some time so if you would only use it for this single use case, I would rather go for method 1.


问:
Google Apps Script Web App not working
I'm experimenting with Google Apps Scripts webapps. I've just got sidebars working and they're very useful but when I try to do a simple webapp, the code shows in the app instead of being executed:

It must be something simple, but it's always simple when you know how.

Thanks for any help. ~

答:
You need to use the template service in the HtmlService.

https://developers.google.com/apps-script/guides/html/templates

code.gs

```<code>function doGet() {
  var html= HtmlService
      .createTemplateFromFile('Index');
      html.name = 'Bob';
      return html.evaluate();
}
</code>```

Index.html

```<code><!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?=name?>!</b>
  </body>
</html>
</code>```

Title: Google Apps Script Web App not working

Body:
You need to use the template service in the HtmlService.

https://developers.google.com/apps-script/guides/html/templates

code.gs

function doGet() {
  var html= HtmlService
      .createTemplateFromFile('Index');
      html.name = 'Bob';
      return html.evaluate();
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?=name?>!</b>
  </body>
</html>


问:
Question on using List
I created an List like this

```<code>List<Dictionary<DicKeyCla, DicValCla>>

public Class DicKeyCla
{
   public EnKey1 DicKeyItem1,
   public EnKey2 DicKeyItem2,
}

public enum EnKey1
{
   A1,
   A2,
   A3,
   A4,
   A5
}

public enum EnKey2
{
   B11,
   B12,
   B13,
   B14,
   B15,
   B16,
   B17,
   B18,
   B19,
}
</code>```

As I know, there is contains() method available for List class.

If I called an function which argues contain the DicKeyCla members like A3 and B15.

How can I pick out the entirely dictionary member from the Top level List rapidly?

I need do more operation on dictionary member.

答:
I have a strange feeling (but I'm probably wrong) that you wrapped your Dictionary with a List hoping you could search the 1 instance of the dictionary with the Contains method and all you want is to access the dictionary members by a combination of EnKey1 and EnKey2. Something like this:</p>

```<code>public struct Key // note the struct...
{
    public static Key A(EnKey1 k1, EnKey2 k2)
    {
       Key k = new Key();
       k.Key1 = k1;
       k.Key2 = k2;
       return k;
    }
    public EnKey1 Key1;
    public EnKey2 Key2;
}

Dictionary<Key, string> dic = new Dictionary<Key, string>();
dic.Add(Key.A(EnKey1.A1,EnKey2.B19), "test");
Console.WriteLine(dic[Key.A(EnKey1.A1,EnKey2.B19)]);
// outputs "test"
// then you can do:
// dic.ContainsKey(Key.A(EnKey1.A1,EnKey2.B19)) -> true
// dic.ContainsKey(Key.A(EnKey1.A2,EnKey2.B19)) -> false
</code>```

Title: Question on using List

Body:
I created an List like this

List<Dictionary<DicKeyCla, DicValCla>>

public Class DicKeyCla
{
   public EnKey1 DicKeyItem1,
   public EnKey2 DicKeyItem2,
}

public enum EnKey1
{
   A1,
   A2,
   A3,
   A4,
   A5
}

public enum EnKey2
{
   B11,
   B12,
   B13,
   B14,
   B15,
   B16,
   B17,
   B18,
   B19,
}

As I know, there is contains() method available for List class.

If I called an function which argues contain the DicKeyCla members like A3 and B15.

How can I pick out the entirely dictionary member from the Top level List rapidly?

I need do more operation on dictionary member.

Body:
I have a strange feeling (but I'm probably wrong) that you wrapped your Dictionary with a List hoping you could search the 1 instance of the dictionary with the Contains method and all you want is to access the dictionary members by a combination of EnKey1 and EnKey2. Something like this:

public struct Key // note the struct...
{
    public static Key A(EnKey1 k1, EnKey2 k2)
    {
       Key k = new Key();
       k.Key1 = k1;
       k.Key2 = k2;
       return k;
    }
    public EnKey1 Key1;
    public EnKey2 Key2;
}

Dictionary<Key, string> dic = new Dictionary<Key, string>();
dic.Add(Key.A(EnKey1.A1,EnKey2.B19), "test");
Console.WriteLine(dic[Key.A(EnKey1.A1,EnKey2.B19)]);
// outputs "test"
// then you can do:
// dic.ContainsKey(Key.A(EnKey1.A1,EnKey2.B19)) -> true
// dic.ContainsKey(Key.A(EnKey1.A2,EnKey2.B19)) -> false


问:
How to update TextView on UI from the class which using runnable interface?
```<code>public class Stopper implements  Runnable {

     private  long mStartTime;
     private volatile int since;
     private Handler handler;
     private TextView tv;
     private Activity activity;
     private Context context;

    /*
    * Constants
    * */
        public static final int MILISEC_TO_MINUTE = 60000;
        public static final int MILISEC_TO_HOUR = 3600000;

    /*
    * Flags
    * */
        private boolean mIsRunning;

        public Stopper(){
          //this.context = context;
            activity = (Activity)context;
            Message message = Message.obtain();
            handler = new Handler(Looper.getMainLooper());

        }
        public void start(){
            mStartTime = System.currentTimeMillis();
            mIsRunning = true;

        }
        public void stop(){
            mIsRunning = false;
        }

        @Override
        public void run () {
            while (mIsRunning) {
                        since = (int)(System.currentTimeMillis() - mStartTime);
                        int hours =  (since / MILISEC_TO_HOUR) % 24; // ms -> h; 360 000= 1[h]
                        int minutes =  (since / MILISEC_TO_MINUTE) % 60;// ms -> min; 60 000[ms] = 1[min]
                        int seconds =  (since / 1000) % 60; //  ms -> s ;1 000[ms] = 1[s] -> (1000 [ms] /1000)%60 = 1[s]
                        int ms =  since % 1000;

                tv.setText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));

                //((Activity) context).updateTimerText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));
            }
        }
    public void getStooperTextView(TextView textView)
    {
        this.tv = textView;
    }

    public int getSince() {
        return since;
    }
}
</code>```

I read some tutorial about chronometer. It works fine until I started needing to use chronometer in two diffrent Activity. The below line of code requires returned value.

```<code>((Activity) context).updateTimerText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));
</code>```

So, I try to use the Handler class, but to do it I need a runnable object.

答: I believe the method Activity#runOnUiThread is what you need

Body:
public class Stopper implements  Runnable {

     private  long mStartTime;
     private volatile int since;
     private Handler handler;
     private TextView tv;
     private Activity activity;
     private Context context;

    /*
    * Constants
    * */
        public static final int MILISEC_TO_MINUTE = 60000;
        public static final int MILISEC_TO_HOUR = 3600000;

    /*
    * Flags
    * */
        private boolean mIsRunning;

        public Stopper(){
          //this.context = context;
            activity = (Activity)context;
            Message message = Message.obtain();
            handler = new Handler(Looper.getMainLooper());

        }
        public void start(){
            mStartTime = System.currentTimeMillis();
            mIsRunning = true;

        }
        public void stop(){
            mIsRunning = false;
        }

        @Override
        public void run () {
            while (mIsRunning) {
                        since = (int)(System.currentTimeMillis() - mStartTime);
                        int hours =  (since / MILISEC_TO_HOUR) % 24; // ms -> h; 360 000= 1[h]
                        int minutes =  (since / MILISEC_TO_MINUTE) % 60;// ms -> min; 60 000[ms] = 1[min]
                        int seconds =  (since / 1000) % 60; //  ms -> s ;1 000[ms] = 1[s] -> (1000 [ms] /1000)%60 = 1[s]
                        int ms =  since % 1000;

                tv.setText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));

                //((Activity) context).updateTimerText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));
            }
        }
    public void getStooperTextView(TextView textView)
    {
        this.tv = textView;
    }

    public int getSince() {
        return since;
    }
}

I read some tutorial about chronometer. It works fine until I started needing to use chronometer in two diffrent Activity. The below line of code requires returned value.

((Activity) context).updateTimerText(String.format("%02d:%02d:%02d:%03d", hours, minutes, seconds, ms));

So, I try to use the Handler class, but to do it I need a runnable object.


问:
How to get a button element made in the DOM, run a function
I created a button element using javascript, and now would like to know how to find that element or select it and get it to call this function:</p>

```<code>    function test() {
      alert("it works!");
    }
</code>```

答:
Use addEventListener:

```<code>var btn = document.createElement("BUTTON");
var t = document.createTextNode("ok");
btn.appendChild(t);
document.body.appendChild(btn);

btn.addEventListener('click', test);

// My Test Function
function test() {
  alert("it works!");
}
</code>```

Body:
I created a button element using javascript, and now would like to know how to find that element or select it and get it to call this function:

    function test() {
      alert("it works!");
    }

Body:
Use addEventListener:

var btn = document.createElement("BUTTON");
var t = document.createTextNode("ok");
btn.appendChild(t);
document.body.appendChild(btn);

btn.addEventListener('click', test);

// My Test Function
function test() {
  alert("it works!");
}


问:
Turn Off Tab for Typeahead.js
I am using a typeahead on one of my text boxes(typeahead.js), and I am trying to turn off the tabbing auto complete. I couldn't find this in the documentation, but perhaps someone knows if/how this is possible?

Any suggestions?

EDIT :

Code used for plug in:

```<code>myTypeAhead = $('#txtTypeAhead').typeahead({
            name: 'TypeAhead',
            valueKey: "Value",
            remote: '/ServiceHandlers/myHandler.ashx?Method=Method&Query=%QUERY',
            template: ['<p>{{Value}}</p>'],
            engine: Hogan
        });

        companyCodeTypeAhead.on('typeahead:initialized', function (evt)
        {
            console.log('INIT ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:opened', function (evt)
        {
            console.log('OPEN ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:closed', function (evt)
        {
            console.log('CLOSE ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:selected', function (evt, data)
        {
            console.log('SELECT data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });
        companyCodeTypeAhead.on('typeahead:autocompleted', function (evt, data)
        {
            console.log('AUTOCOMPLETE data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });
</code>```

答:
I wanted the same thing, autocomplete but have the tab NOT select the first option in the list. This was not possible without hacking the actual package which make it not very maintainable.  So I went a different route and added a custom dataset that returns the current query as the first result...

var substringMatcher = function(strs) {
  return function findMatches(q, cb) {
    var matches, substrRegex;

    // an array that will be populated with substring matches
    matches = [];

    // regex used to determine if a string contains the substring `q`
    substrRegex = new RegExp(q, 'i');

    // iterate through the pool of strings and for any string that
    // contains the substring `q`, add it to the `matches` array
    $.each(strs, function(i, str) {
      if (substrRegex.test(str)) {
        // the typeahead jQuery plugin expects suggestions to a
        // JavaScript object, refer to typeahead docs for more info
        matches.push({
          value: str
        });
      }
    });

    cb(matches);
  };
};
var getLocalSource = function() {
  return function findMatches(query, callback) {
    return callback([{
      'data': query
    }]);
  }
};
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
  'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
  'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
  'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
  'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
  'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
  'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];

var countries = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"];

$('#the-basics .typeahead').typeahead({
  hint: true,
  highlight: true,
  minLength: 1
}, {
  name: 'local-data',
  display: 'data',
  source: getLocalSource()
}, {
  name: 'states',
  displayKey: 'value',
  source: substringMatcher(states),
  templates: {
    header: '
States
'
  }
}, {
  name: 'countries',
  displayKey: 'value',
  source: substringMatcher(countries),
  templates: {
    header: '
Countries
'
  }
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.tt-dataset .head {
  padding: 15px;
  font-weight: bold;
  background-color: lightgray;
}</code>```

<link href="https://twitter.github.io/typeahead.js/css/examples.css" rel="stylesheet" />

  <input class="typeahead" type="text" placeholder="Locations">

```

Title: Turn Off Tab for Typeahead.js

Body:
I am using a typeahead on one of my text boxes(typeahead.js), and I am trying to turn off the tabbing auto complete. I couldn't find this in the documentation, but perhaps someone knows if/how this is possible?

Any suggestions?

EDIT :

Code used for plug in:

myTypeAhead = $('#txtTypeAhead').typeahead({
            name: 'TypeAhead',
            valueKey: "Value",
            remote: '/ServiceHandlers/myHandler.ashx?Method=Method&Query=%QUERY',
            template: ['
{{Value}}
'],
            engine: Hogan
        });

        companyCodeTypeAhead.on('typeahead:initialized', function (evt)
        {
            console.log('INIT ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:opened', function (evt)
        {
            console.log('OPEN ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:closed', function (evt)
        {
            console.log('CLOSE ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:selected', function (evt, data)
        {
            console.log('SELECT data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });
        companyCodeTypeAhead.on('typeahead:autocompleted', function (evt, data)
        {
            console.log('AUTOCOMPLETE data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });

Body:
I wanted the same thing, autocomplete but have the tab NOT select the first option in the list. This was not possible without hacking the actual package which make it not very maintainable.  So I went a different route and added a custom dataset that returns the current query as the first result...

var substringMatcher = function(strs) {
  return function findMatches(q, cb) {
    var matches, substrRegex;

    // an array that will be populated with substring matches
    matches = [];

    // regex used to determine if a string contains the substring `q`
    substrRegex = new RegExp(q, 'i');

    // iterate through the pool of strings and for any string that
    // contains the substring `q`, add it to the `matches` array
    $.each(strs, function(i, str) {
      if (substrRegex.test(str)) {
        // the typeahead jQuery plugin expects suggestions to a
        // JavaScript object, refer to typeahead docs for more info
        matches.push({
          value: str
        });
      }
    });

    cb(matches);
  };
};
var getLocalSource = function() {
  return function findMatches(query, callback) {
    return callback([{
      'data': query
    }]);
  }
};
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
  'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
  'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
  'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
  'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
  'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
  'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];

var countries = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"];

$('#the-basics .typeahead').typeahead({
  hint: true,
  highlight: true,
  minLength: 1
}, {
  name: 'local-data',
  display: 'data',
  source: getLocalSource()
}, {
  name: 'states',
  displayKey: 'value',
  source: substringMatcher(states),
  templates: {
    header: '<div class="head">States</div>'
  }
}, {
  name: 'countries',
  displayKey: 'value',
  source: substringMatcher(countries),
  templates: {
    header: '<div class="head">Countries</div>'
  }
});

.tt-dataset .head {
  padding: 15px;
  font-weight: bold;
  background-color: lightgray;
}

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
<link href="https://twitter.github.io/typeahead.js/css/examples.css" rel="stylesheet" />

<div id="the-basics">
  <input class="typeahead" type="text" placeholder="Locations">
</div>


答:
If you arre not implement all the methods in Chassis keep VehicleChassis as abstract.

You can overload constructor as many as you want.

```<code>public String chassisName;
public VehicleChassis() {
    chassisName = "No";
}
public VehicleChassis(String chassisName) {
    this.chassisName = chassisName;
}
</code>```

If you have another instance variable:

```<code>public VehicleChassis(String chassisName, int price) {
    this.chassisName = chassisName;
    this.price = price;
}
</code>```

For more about constructor overloading read this question answer.

Title: How do I create a public default constructor and an overloaded constructor?

Body:
If you arre not implement all the methods in Chassis keep VehicleChassis as abstract.

You can overload constructor as many as you want.

public String chassisName;
public VehicleChassis() {
    chassisName = "No";
}
public VehicleChassis(String chassisName) {
    this.chassisName = chassisName;
}

If you have another instance variable:

public VehicleChassis(String chassisName, int price) {
    this.chassisName = chassisName;
    this.price = price;
}

For more about constructor overloading read this question answer.


问:
MYSQL: from subquery with where
I'm trying to do this query:

```<code>SET @NUMBER:=0;
SELECT *, @NUMBER:=@NUMBER+1 AS NUMBER FROM(
    SELECT *
    FROM CTBQ
) AS TB1
WHERE TB1.NUMBER > 1
</code>```

but this error happens: Unknown column 'TB1.NUMBER' in 'where clause'

why can't I do this?

can anyone help me?

答:
There is no NUMBER column in TB1 subquery. The column is defined in main query. Therefore you need to use NUMBER instead of TB1.NUMBER. Also, you can use aliases in HAVING clause only. Thus, use folowing:

```<code>SET @NUMBER:=0;
SELECT *, @NUMBER:=@NUMBER+1 AS `NUMBER`
FROM
    (SELECT *
    FROM `measurements`
) AS TB1
GROUP BY `NUMBER`
HAVING `NUMBER`>1;
</code>```

Note, it is possible to use proposed query without GROUP BY clause.

Title: MYSQL: from subquery with where

Body:
I'm trying to do this query:

SET @NUMBER:=0;
SELECT *, @NUMBER:=@NUMBER+1 AS NUMBER FROM(
    SELECT *
    FROM CTBQ
) AS TB1
WHERE TB1.NUMBER > 1

but this error happens: Unknown column 'TB1.NUMBER' in 'where clause'

why can't I do this?

can anyone help me?

Body:
There is no NUMBER column in TB1 subquery. The column is defined in main query. Therefore you need to use NUMBER instead of TB1.NUMBER. Also, you can use aliases in HAVING clause only. Thus, use folowing:

SET @NUMBER:=0;
SELECT *, @NUMBER:=@NUMBER+1 AS `NUMBER`
FROM
    (SELECT *
    FROM `measurements`
) AS TB1
GROUP BY `NUMBER`
HAVING `NUMBER`>1;

Note, it is possible to use proposed query without GROUP BY clause.


问:
IBM IHS Webserver fixpack issue
I am upgraded IBM WebSphere, IHS, Plugins from 8.0.0.9 to 8.0.0.13 after applying Fixpack to IHS it shows some configuration error.

Now when I access the application from IHS URL it showing 404 error.

There is a configuration IHS and node.

The below snapshot shows the issue.

答: It's likely that you simply didn't start the administration server (bin/adminctl start)</p>

Title: IBM IHS Webserver fixpack issue


答:
you can do the following to apply a click function to your button;</p>

```<code>$(btn).on('click', test);
</code>```

Title: How to get a button element made in the DOM, run a function

Body:
you can do the following to apply a click function to your button;

$(btn).on('click', test);


问:
Java: Long result = -1: cannot convert from int to long
I'm using eclipse java ee to perform java programming.

I had the following line of code in one of my functions:

```<code>Long result = -1;
</code>```

I got the following error:

Type mismatch: cannot convert from int to Long

I can't quite understand why when i add a number to the variable it provides this error.

How can this issue be resolved and why did it happen in the first place?

答:
To specify a constant of type long, suffix it with an L:

```<code>Long result = -1L;
</code>```

Without the L, the interpreter types the constant number as an int, which is not the same type as a long.

Body:
I'm using eclipse java ee to perform java programming.

I had the following line of code in one of my functions:

Long result = -1;

I got the following error:

Type mismatch: cannot convert from int to Long

I can't quite understand why when i add a number to the variable it provides this error.

How can this issue be resolved and why did it happen in the first place?

Body:
To specify a constant of type long, suffix it with an L:

Long result = -1L;

Without the L, the interpreter types the constant number as an int, which is not the same type as a long.


问:
Create New Field in Access
I have a large table of messy data. It has numerous different values in the use % column where there should only be one. I want to create a new field which shows only one use percentage per ID; the lowest valid use percentage. null is not a valid use percentage. where there is only one use percentage and it is null, I want to change it to 0.

```<code>+--------------------------+
| ID | Current Use % Field |
+--------------------------+
| 01 | 20%                 |
| 01 | Null                |
| 01 | 0                   |
| 02 | 40%                 |
| 02 | Null                |
| 03 | 50%                 |
| 03 | 5%                  |
| 04 | Null                |
+--------------------------+

+--------------------------+
| ID | Desired Use % Field |
+--------------------------+
| 01 | 0                   |
| 02 | 40%                 |
| 03 | 5%                  |
| 04 | 0                   |
+--------------------------+
</code>```

Please can someone suggest how to approach this complex query in access using SQL? I have been trying to manipulate this in excel but there are far too many records for my computer to handle.

Kind regards,

答:
Try:

```<code>SELECT ID, MIN(Use)
FROM Table
WHERE Use <> "Null"
GROUP BY ID
</code>```

The above assumes that the column is a text field. If its a number field, then change your where to: WHERE Use IS NOT NULL

Title: Create New Field in Access

Body:
I have a large table of messy data. It has numerous different values in the use % column where there should only be one. I want to create a new field which shows only one use percentage per ID; the lowest valid use percentage. null is not a valid use percentage. where there is only one use percentage and it is null, I want to change it to 0.

+--------------------------+
| ID | Current Use % Field |
+--------------------------+
| 01 | 20%                 |
| 01 | Null                |
| 01 | 0                   |
| 02 | 40%                 |
| 02 | Null                |
| 03 | 50%                 |
| 03 | 5%                  |
| 04 | Null                |
+--------------------------+

+--------------------------+
| ID | Desired Use % Field |
+--------------------------+
| 01 | 0                   |
| 02 | 40%                 |
| 03 | 5%                  |
| 04 | 0                   |
+--------------------------+

Please can someone suggest how to approach this complex query in access using SQL? I have been trying to manipulate this in excel but there are far too many records for my computer to handle.

Kind regards,

Body:
Try:

SELECT ID, MIN(Use)
FROM Table
WHERE Use <> "Null"
GROUP BY ID

The above assumes that the column is a text field. If its a number field, then change your where to: WHERE Use IS NOT NULL


问:
How to make div come under another div
How can I make DIV "sideBottom" go under "SideTop" and "console " go under "Main"?

This is how it looks at the moment:

HTML/CSS:

*{
    padding : 0;
    margin : 0;
    border : 0;
}
body{
    background-image : url(' bi-background-cubes.png ');
    background-attachment : fixed;
    background-size : 100% auto;
}
.blended_grid{
    display : block;
    width : 1370px;
    overflow : auto;
    margin : 50px auto 0 auto;
}
.pageHeader{
    background-color : rgba(6,67,0,0.4);
    float : left;
    clear : none;
    height : 70px;
    width : 1370px;
}
.sideTop{
    background-color : rgba(0,2,227,0.4);
    float : left;
    clear : none;
    height : 430px;
    width : 260px;
}
.main{
    background-color : rgba(171,0,161,0.4);
    float : left;
    clear : none;
    height : 600px;
    width : 680px;
}
.tableInput{
    background-color : rgba(156,141,0,0.4);
    float : left;
    clear : none;
    height : 350px;
    width : 400px;
}
.tableOutput{
    clear : none;
    float : left;
    position : relative;
    width : 400px;
    height : 350px;
    background-color : rgba(0,115,97,0.4);
}
.sideBottom{
    clear : none;
    float : left;
    position : relative;
    width : 260px;
    height : 270px;
    background-color : rgba(255,0,10,0.4);
}
.console{
    background-color : lightgreen;
    float : left;
    clear : none;
    height : 100px;
    width : 680px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="blended_grid">
  <div class="pageHeader">`
    <h1> pageHeader</h1>
  </div>
  <div class="sideTop">
    <h1> SideTop </h1>
  </div>

  <div class="main">
    <h1> Main </h1>
  </div>
  <div class="tableInput">
    <h1>tableInput</h1>
  </div>

  <div class="tableOutput">
    <h1> tableOutput</h1>
  </div>
  <div class="sideBottom">
    <h1> SideBottom</h1>
  </div>
  <div class="console">
    <h1>  Console</h1>
  </div>
</div></code>```

答:
Get rid of the floats, add some wrapping divs, and use flex:

I assume this is what you want:  https://jsfiddle.net/znvuepLq/

Here's a good resource for flex:  https://css-tricks.com/snippets/css/a-guide-to-flexbox/

HTML/CSS:

*{
  padding : 0;
  margin : 0;
  border : 0;
}
body{
  background-image : url(' bi-background-cubes.png ');
  background-attachment : fixed;
  background-size : 100% auto;
}
.blended_grid{
  width : 1370px;
  overflow : auto;
  margin : 50px auto 0 auto;
}
.content{
  display: flex;
}
.pageHeader{
  background-color : rgba(6,67,0,0.4);
  height : 70px;
  width : 1370px;
}
.sideTop{
  background-color : rgba(0,2,227,0.4);
  height : 430px;
  width : 260px;
}
.main{
  background-color : rgba(171,0,161,0.4);
  height : 600px;
  width : 680px;
}
.tableInput{
  background-color : rgba(156,141,0,0.4);
  height : 350px;
  width : 400px;
}
.tableOutput{
  width : 400px;
  height : 350px;
  background-color : rgba(0,115,97,0.4);
}
.sideBottom{
  width : 260px;
  height : 270px;
  background-color : rgba(255,0,10,0.4);
}
.console{
  background-color : lightgreen;
  height : 100px;
  width : 680px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="blended_grid">
  <div class="pageHeader">`
    <h1> pageHeader</h1>
  </div>
  <div class="content">
    <div>
      <div class="sideTop">
        <h1> SideTop </h1>
      </div>
      <div class="sideBottom">
        <h1> SideBottom</h1>
      </div>
    </div>
    <div>
      <div class="main">
        <h1> Main </h1>
      </div>
      <div class="console">
        <h1>  Console</h1>
      </div>
    </div>
    <div>
      <div class="tableInput">
        <h1>tableInput</h1>
      </div>
      <div class="tableOutput">
        <h1> tableOutput</h1>
      </div>
    </div>
  </div>
</div></code>```

Title: How to make div come under another div

Body:
How can I make DIV "sideBottom" go under "SideTop" and "console " go under "Main"?

This is how it looks at the moment:

HTML/CSS:

*{
    padding : 0;
    margin : 0;
    border : 0;
}
body{
    background-image : url(' bi-background-cubes.png ');
    background-attachment : fixed;
    background-size : 100% auto;
}
.blended_grid{
    display : block;
    width : 1370px;
    overflow : auto;
    margin : 50px auto 0 auto;
}
.pageHeader{
    background-color : rgba(6,67,0,0.4);
    float : left;
    clear : none;
    height : 70px;
    width : 1370px;
}
.sideTop{
    background-color : rgba(0,2,227,0.4);
    float : left;
    clear : none;
    height : 430px;
    width : 260px;
}
.main{
    background-color : rgba(171,0,161,0.4);
    float : left;
    clear : none;
    height : 600px;
    width : 680px;
}
.tableInput{
    background-color : rgba(156,141,0,0.4);
    float : left;
    clear : none;
    height : 350px;
    width : 400px;
}
.tableOutput{
    clear : none;
    float : left;
    position : relative;
    width : 400px;
    height : 350px;
    background-color : rgba(0,115,97,0.4);
}
.sideBottom{
    clear : none;
    float : left;
    position : relative;
    width : 260px;
    height : 270px;
    background-color : rgba(255,0,10,0.4);
}
.console{
    background-color : lightgreen;
    float : left;
    clear : none;
    height : 100px;
    width : 680px;
}

`

 pageHeader

 SideTop

 Main

tableInput

 tableOutput

 SideBottom

  Console

Body:
Get rid of the floats, add some wrapping divs, and use flex:

I assume this is what you want:  https://jsfiddle.net/znvuepLq/

Here's a good resource for flex:  https://css-tricks.com/snippets/css/a-guide-to-flexbox/

HTML/CSS:

*{
  padding : 0;
  margin : 0;
  border : 0;
}
body{
  background-image : url(' bi-background-cubes.png ');
  background-attachment : fixed;
  background-size : 100% auto;
}
.blended_grid{
  width : 1370px;
  overflow : auto;
  margin : 50px auto 0 auto;
}
.content{
  display: flex;
}
.pageHeader{
  background-color : rgba(6,67,0,0.4);
  height : 70px;
  width : 1370px;
}
.sideTop{
  background-color : rgba(0,2,227,0.4);
  height : 430px;
  width : 260px;
}
.main{
  background-color : rgba(171,0,161,0.4);
  height : 600px;
  width : 680px;
}
.tableInput{
  background-color : rgba(156,141,0,0.4);
  height : 350px;
  width : 400px;
}
.tableOutput{
  width : 400px;
  height : 350px;
  background-color : rgba(0,115,97,0.4);
}
.sideBottom{
  width : 260px;
  height : 270px;
  background-color : rgba(255,0,10,0.4);
}
.console{
  background-color : lightgreen;
  height : 100px;
  width : 680px;
}

<div class="blended_grid">
  <div class="pageHeader">`
    <h1> pageHeader</h1>
  </div>
  <div class="content">
    <div>
      <div class="sideTop">
        <h1> SideTop </h1>
      </div>
      <div class="sideBottom">
        <h1> SideBottom</h1>
      </div>
    </div>
    <div>
      <div class="main">
        <h1> Main </h1>
      </div>
      <div class="console">
        <h1>  Console</h1>
      </div>
    </div>
    <div>
      <div class="tableInput">
        <h1>tableInput</h1>
      </div>
      <div class="tableOutput">
        <h1> tableOutput</h1>
      </div>
    </div>
  </div>
</div>


问:
D3 SVG with finite height and width
I want to create work space, in which have to use D3 SVG with fixed width and height. Normally, this svg is infinite in both dimensions. In below example, circle element is draggable upto any position(even outside) in viewport.

fiddle link:
    https://jsfiddle.net/313vhqdx/

```<code>var container = d3.select("body")
                .append("svg")
                  .attr("id", "svgcontainer")
                  .attr("width", 300)
                  .attr("height", 300)
                  .style("background-color", "blue")
                  .call(zoom)
                .append("g");
</code>```

But in my case, I need to set fixed width and height for SVG. Is it possible?

答:
No, SVG itself always has conceptually infinite coordinates. But in d3 since version 4 you can easily restrict the zoom/drag with zoom.translateExtent:

```<code>var zoom = d3.zoom()
    .translateExtent([[-100, -100], [400, 400]])
    .scaleExtent([0, 2])
    .on("zoom", function () {
        container.attr("transform", d3.event.transform);
    });
</code>```

Since jsfiddle only loads d3 version 3, here is a CodePen.

Title: D3 SVG with finite height and width

Body:
I want to create work space, in which have to use D3 SVG with fixed width and height. Normally, this svg is infinite in both dimensions. In below example, circle element is draggable upto any position(even outside) in viewport.

fiddle link:
    https://jsfiddle.net/313vhqdx/

var container = d3.select("body")
                .append("svg")
                  .attr("id", "svgcontainer")
                  .attr("width", 300)
                  .attr("height", 300)
                  .style("background-color", "blue")
                  .call(zoom)
                .append("g");

But in my case, I need to set fixed width and height for SVG. Is it possible?

Body:
No, SVG itself always has conceptually infinite coordinates. But in d3 since version 4 you can easily restrict the zoom/drag with zoom.translateExtent:

var zoom = d3.zoom()
    .translateExtent([[-100, -100], [400, 400]])
    .scaleExtent([0, 2])
    .on("zoom", function () {
        container.attr("transform", d3.event.transform);
    });

Since jsfiddle only loads d3 version 3, here is a CodePen.


答:
Another option with jquery:

var btn = document.createElement("BUTTON");
var t = document.createTextNode("ok");
btn.appendChild(t);
document.body.appendChild(btn);

$('body').on('click', 'BUTTON', function(event) {
  alert("it works!");
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></code>```

Body:
Another option with jquery:

var btn = document.createElement("BUTTON");
var t = document.createTextNode("ok");
btn.appendChild(t);
document.body.appendChild(btn);

$('body').on('click', 'BUTTON', function(event) {
  alert("it works!");
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


答:
```<code>Long result = -1L;
</code>```

Title: Java: Long result = -1: cannot convert from int to long

Body: Long result = -1L;


问:
How not to overwrite a file
I save text into .txt-file. Afterwards I want to add some new text to the file. If I run the code to write new text,  it overwrites the old content. How can I prevent this?</p>

```<code>using UnityEngine;
using System.IO;

public class Level02WON : MonoBehaviour
{
    void OnTriggerEnter()
    {
        string line = "Level02 = true";
        System.IO.StreamWriter file =
           new System.IO.StreamWriter(@"C:\Users\Public\Cubator\Level Data\Level02DATA.txt");
        file.WriteLine(line);
        file.Close();
    }

}
</code>```

答:
You should use another constructor of StreamWriter, that allows appending, like this:</p>

```<code>StreamWriter writer = new StreamWriter(path, true);
</code>```

Title: How not to overwrite a file

Body:
I save text into .txt-file. Afterwards I want to add some new text to the file. If I run the code to write new text,  it overwrites the old content. How can I prevent this?

using UnityEngine;
using System.IO;

public class Level02WON : MonoBehaviour
{
    void OnTriggerEnter()
    {
        string line = "Level02 = true";
        System.IO.StreamWriter file =
           new System.IO.StreamWriter(@"C:\Users\Public\Cubator\Level Data\Level02DATA.txt");
        file.WriteLine(line);
        file.Close();
    }

}

Body:
You should use another constructor of StreamWriter, that allows appending, like this:

StreamWriter writer = new StreamWriter(path, true);