问:
horizontal direction of Floating action menu
I need a float action menu with horizontal direction, I found this library
but it's linked to listview and not what I look for, I tested 'com.github.clans:fab:1.6.4' it's really good but always no horizontal direction.

any idea to find out ?

答:
Thank's @Mayank for the code and the idea, for everyone with the same problem, this the code :

```<code>     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:gravity="center"
            android:padding="6dp"

            >
            <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/parentlayout"

                android:layout_gravity="left"
                android:fitsSystemWindows="true"
                android:clipChildren="false"
                android:clipToPadding="false"
                >
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab"

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_marginRight="120dp"

                    app:backgroundTint="@color/TealDark"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:pressedTranslationZ="-12dp"
                    android:src="@drawable/fab_add"
                    />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginRight="90dp"
                    android:visibility="invisible"

                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"
                    android:src="@drawable/file_image" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="8dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/filevideo" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-75dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/audiobook" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-158dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/file" />
            </android.support.design.widget.CoordinatorLayout>
        </LinearLayout>
</code>```

for code java I use the same above :

```<code>final FloatingActionButton fab,fab1,fab2, fab3, fab4;
                fab = (FloatingActionButton)conformity_child.findViewById(R.id.fab);
                fab1 = (FloatingActionButton)conformity_child.findViewById(R.id.fab1);
                fab2 = (FloatingActionButton)conformity_child.findViewById(R.id.fab2);
                fab3 = (FloatingActionButton)conformity_child.findViewById(R.id.fab3);
                fab4 = (FloatingActionButton)conformity_child.findViewById(R.id.fab4);
                fab.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(isFabOpen){
                            fab.startAnimation(rotate_backward);
                            fab1.startAnimation(fab_close);
                            fab2.startAnimation(fab_close);
                            fab3.startAnimation(fab_close);
                            fab4.startAnimation(fab_close);
                            fab1.setClickable(false);
                            fab2.setClickable(false);
                            fab3.setClickable(false);
                            fab4.setClickable(false);
                            isFabOpen = false;

                        } else {
                            fab.startAnimation(rotate_forward);
                            fab1.startAnimation(fab_open);
                            fab2.startAnimation(fab_open);
                            fab3.startAnimation(fab_open);
                            fab4.startAnimation(fab_open);
                            fab1.setClickable(true);
                            fab2.setClickable(true);
                            fab3.setClickable(true);
                            fab4.setClickable(true);
                            isFabOpen = true;
                        }
                    }
                });
</code>```

animation : fab_close

```<code><?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="300"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="0.8"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale="0.8" />
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="300"/>
</set>
</code>```

animation : fab_open

```<code> <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="300"
        android:fromXScale="0.8"
        android:fromYScale="0.8"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale="0.0" />
    <alpha android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="300"/>
</set>
</code>```

Body:
Thank's @Mayank for the code and the idea, for everyone with the same problem, this the code :

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:gravity="center"
            android:padding="6dp"

            >
            <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/parentlayout"

                android:layout_gravity="left"
                android:fitsSystemWindows="true"
                android:clipChildren="false"
                android:clipToPadding="false"
                >
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab"

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_marginRight="120dp"

                    app:backgroundTint="@color/TealDark"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:pressedTranslationZ="-12dp"
                    android:src="@drawable/fab_add"
                    />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginRight="90dp"
                    android:visibility="invisible"

                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"
                    android:src="@drawable/file_image" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="8dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/filevideo" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-75dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/audiobook" />
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-158dp"
                    android:layout_gravity="bottom"
                    android:visibility="invisible"
                    app:elevation="6dp"
                    app:fabSize="mini"
                    app:backgroundTint="@color/TealDark"
                    app:pressedTranslationZ="-12dp"

                    android:src="@drawable/file" />
            </android.support.design.widget.CoordinatorLayout>
        </LinearLayout>

for code java I use the same above :

final FloatingActionButton fab,fab1,fab2, fab3, fab4;
                fab = (FloatingActionButton)conformity_child.findViewById(R.id.fab);
                fab1 = (FloatingActionButton)conformity_child.findViewById(R.id.fab1);
                fab2 = (FloatingActionButton)conformity_child.findViewById(R.id.fab2);
                fab3 = (FloatingActionButton)conformity_child.findViewById(R.id.fab3);
                fab4 = (FloatingActionButton)conformity_child.findViewById(R.id.fab4);
                fab.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(isFabOpen){
                            fab.startAnimation(rotate_backward);
                            fab1.startAnimation(fab_close);
                            fab2.startAnimation(fab_close);
                            fab3.startAnimation(fab_close);
                            fab4.startAnimation(fab_close);
                            fab1.setClickable(false);
                            fab2.setClickable(false);
                            fab3.setClickable(false);
                            fab4.setClickable(false);
                            isFabOpen = false;

                        } else {
                            fab.startAnimation(rotate_forward);
                            fab1.startAnimation(fab_open);
                            fab2.startAnimation(fab_open);
                            fab3.startAnimation(fab_open);
                            fab4.startAnimation(fab_open);
                            fab1.setClickable(true);
                            fab2.setClickable(true);
                            fab3.setClickable(true);
                            fab4.setClickable(true);
                            isFabOpen = true;
                        }
                    }
                });

animation : fab_close

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="300"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="0.8"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale="0.8" />
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="300"/>
</set>

animation : fab_open

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="300"
        android:fromXScale="0.8"
        android:fromYScale="0.8"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale="0.0" />
    <alpha android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="300"/>
</set>


来源: stackexchange

问:
Print the value of a tensor in Tensorflow
The following is the link to my full code:

https://github.com/roshanDD/YAD2K/blob/master/yad2k/models/keras_yolo.py#L253

I just wanna print out the value of the tensor, called true_areas. I ran my code:

```<code>sess = tf.InteractiveSession()
true_areas = true_wh[..., 0] * true_wh[..., 1]
tf.Print(true_areas, [true_areas], message = "This is True Areas: ")
b = tf.add(true_areas, true_areas).eval()
</code>```

But it gives me the error:

```<code>Caused by op 'input_2', defined at:
  File "learning.py", line 358, in <module>
    _main(args)
  File "learning.py", line 66, in _main
    model_body, model = create_model(anchors, class_names)
  File "learning.py", line 185, in create_model
    boxes_input = Input(shape=(None, 5))
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1388, in Input
    input_tensor=tensor)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1299, in __init__
    name=self.name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 349, in placeholder
    x = tf.placeholder(dtype, shape=shape, name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1507, in placeholder
    name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1997, in _placeholder
    name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_2' with dtype float
     [[Node: input_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
</code>```

What is that placeholder it's talking about?

答:
The error messages tells you, that somewhere in your code you defined a tf.placeholder() called input_2.

You need to feed values to this placeholder when you want to evaluate a graph that depends on this placeholder. It should look something like this:

```<code>b = tf.add(true_areas, true_areas).eval({input_2: someInputValues})
</code>```

ContentLicense: CC BY-SA 3.0

Body:
The following is the link to my full code:

https://github.com/roshanDD/YAD2K/blob/master/yad2k/models/keras_yolo.py#L253

I just wanna print out the value of the tensor, called true_areas. I ran my code:

sess = tf.InteractiveSession()
true_areas = true_wh[..., 0] * true_wh[..., 1]
tf.Print(true_areas, [true_areas], message = "This is True Areas: ")
b = tf.add(true_areas, true_areas).eval()

But it gives me the error:

Caused by op 'input_2', defined at:
  File "learning.py", line 358, in <module>
    _main(args)
  File "learning.py", line 66, in _main
    model_body, model = create_model(anchors, class_names)
  File "learning.py", line 185, in create_model
    boxes_input = Input(shape=(None, 5))
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1388, in Input
    input_tensor=tensor)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1299, in __init__
    name=self.name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 349, in placeholder
    x = tf.placeholder(dtype, shape=shape, name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1507, in placeholder
    name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1997, in _placeholder
    name=name)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_2' with dtype float
     [[Node: input_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

What is that placeholder it's talking about?

Body:
The error messages tells you, that somewhere in your code you defined a tf.placeholder() called input_2.

You need to feed values to this placeholder when you want to evaluate a graph that depends on this placeholder. It should look something like this:

b = tf.add(true_areas, true_areas).eval({input_2: someInputValues})


问:
JS onclick() not called at all in IE
I've created a drop-down menu with HTML and JS. When I run it in Chrome it works great, but it doesn't work in IE. The onclick() function doesn't seem to be called at all.

The options tags within the select tag look like this:

```<code><option value="?id=3" onclick="hideDropDown();return false;">Option 3</option>
</code>```

but hideDropDown() never gets run in IE (I've checked using an alert() within the function).

The same for:

```<code><option value="?id=2" onclick="alert('hi'); return false;">Option 2</option>
</code>```

clicking on 'Option 2' in this case does not bring up an alert.

I've read a lot online about onclick() not working in IE, but none of the answers I've seen have worked for me. Does anybody have any suggestions?

答:
I cannot understand why you want to return false after function call.
Maybe you can return false from the function.

So the code will be:

```<code>function hideDropDown() {
  //enter code here
return false;
}
</code>```

Title: JS onclick() not called at all in IE

Body:
I've created a drop-down menu with HTML and JS. When I run it in Chrome it works great, but it doesn't work in IE. The onclick() function doesn't seem to be called at all.

The options tags within the select tag look like this:

<option value="?id=3" onclick="hideDropDown();return false;">Option 3</option>

but hideDropDown() never gets run in IE (I've checked using an alert() within the function).

The same for:

<option value="?id=2" onclick="alert('hi'); return false;">Option 2</option>

clicking on 'Option 2' in this case does not bring up an alert.

I've read a lot online about onclick() not working in IE, but none of the answers I've seen have worked for me. Does anybody have any suggestions?

Body:
I cannot understand why you want to return false after function call.
Maybe you can return false from the function.

So the code will be:

function hideDropDown() {
  //enter code here
return false;
}


问:
ReadFile on volume fails with ERROR_INVALID_PARAMETER after FSCTL_ALLOW_EXTENDED_DASD_IO
I'm reading a volume (logical drive) with ReadFile. I'm using DeviceIoControl with FSCTL_ALLOW_EXTENDED_DASD_IO code, because I want to have access to all (including the last) bytes and had an issue trying to read last 512 bytes (ReadFile successed, but reported 0 bytes read) and saw advice to use it. Unfortunately, ReadFile fails being called after that DeviceIoControl called.
In code it looks like this (all success checks are omitted for the brevity):

```<code>    HANDLE fd;
    DWORD junk;
    int lenToBeRead = 0x1000;
    DWORD nread;
    char* alignedBuf = new char[lenToBeRead];

    fd = CreateFile("path to volume", FILE_READ_DATA,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL, OPEN_EXISTING, 0, NULL)) //success

    DeviceIoControl(fd, FSCTL_ALLOW_EXTENDED_DASD_IO,
      NULL, 0, NULL, 0, &junk, (LPOVERLAPPED) NULL) //success

    ReadFile(fd, alignedBuf, (DWORD) lenToBeRead, &nread, NULL)
     // fails with 0x57 code, ERROR_INVALID_PARAMETER
</code>```

All work with fd handle is synchronous.

EDIT. I solved the problem. I was trying to read last bytes. So my volume was of length L = 0x...200 and I had my handle on position pos = L - 0x200. What I had done before I did the FSCTL_ALLOW_EXTENDED_DASD_IO thing - I cut lenToBeRead to fit in remaining space (so, if it was 0x1000, it would change to 0x200), because I had found that ReadFile did not guarantee read all the bytes to the EOF in case of lenToBeRead is greater than amount of bytes remained from current handle position. This did not help, ReadFilewas still returning with success and 0 bytes read. I deleted that fix and then used FSCTL_ALLOW_EXTENDED_DASD_IO, which deliver me then ReadFile failing with ERROR_INVALID_PARAMETER on lenToBeRead = 0x1000. I totally forgot about the first fix and remembered now and now it works.

答:
I found the solution and add it to the question body.
What one has to keep in mind when working with ReadFile is to control arguments (length) to not cross the boundary of the file.
I had tried it as a fix before doing the FSCTL_ALLOW_EXTENDED_DASD_IO thing and it did not help. But combination of the FSCTL_ALLOW_EXTENDED_DASD_IO thing and the boundary check gave me wanted result - I could read that last bytes.

Body:
I'm reading a volume (logical drive) with ReadFile. I'm using DeviceIoControl with FSCTL_ALLOW_EXTENDED_DASD_IO code, because I want to have access to all (including the last) bytes and had an issue trying to read last 512 bytes (ReadFile successed, but reported 0 bytes read) and saw advice to use it. Unfortunately, ReadFile fails being called after that DeviceIoControl called.
In code it looks like this (all success checks are omitted for the brevity):

    HANDLE fd;
    DWORD junk;
    int lenToBeRead = 0x1000;
    DWORD nread;
    char* alignedBuf = new char[lenToBeRead];

    fd = CreateFile("path to volume", FILE_READ_DATA,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL, OPEN_EXISTING, 0, NULL)) //success

    DeviceIoControl(fd, FSCTL_ALLOW_EXTENDED_DASD_IO,
      NULL, 0, NULL, 0, &junk, (LPOVERLAPPED) NULL) //success

    ReadFile(fd, alignedBuf, (DWORD) lenToBeRead, &nread, NULL)
     // fails with 0x57 code, ERROR_INVALID_PARAMETER

All work with fd handle is synchronous.

EDIT. I solved the problem. I was trying to read last bytes. So my volume was of length L = 0x...200 and I had my handle on position pos = L - 0x200. What I had done before I did the FSCTL_ALLOW_EXTENDED_DASD_IO thing - I cut lenToBeRead to fit in remaining space (so, if it was 0x1000, it would change to 0x200), because I had found that ReadFile did not guarantee read all the bytes to the EOF in case of lenToBeRead is greater than amount of bytes remained from current handle position. This did not help, ReadFilewas still returning with success and 0 bytes read. I deleted that fix and then used FSCTL_ALLOW_EXTENDED_DASD_IO, which deliver me then ReadFile failing with ERROR_INVALID_PARAMETER on lenToBeRead = 0x1000. I totally forgot about the first fix and remembered now and now it works.


问:
How add registry keys with CPACK_PACKAGE_INSTALL_REGISTRY_KEY?
I need to install some registry key for a NSIS installer. I'm working with CPACK and I found this command CPACK_PACKAGE_INSTALL_REGISTRY_KEY. There is not much doc on the Internet but I guess :

```<code>set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"MyReg\\\\MyKey" "${INSTALL_DIR}\\\\"
)
</code>```

Or something not much different.

I also read this on an other topic:

```<code>list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
                InstallDirRegKey HKCU \"Software\\Test\" \"RegEntry\"
               ")
</code>```

But I didn't understand why use this last command instead of the CPACK command.

Thank you for your help

答:
I don't know anything about CPack but I guess CPACK_PACKAGE_INSTALL_REGISTRY_KEY also maps to InstallDirRegKey and cannot be used to write generic values to the registry. </p>

<p>Try something like this to insert raw NSIS instructions: </p>

```<code>SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  WriteRegStr HKLM 'Software\\\\MyApp' 'MyValue' 'MyData'
  WriteRegDWORD HKLM 'Software\\\\MyApp' 'OtherValue' '4'
   ")
SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
  DeleteRegKey HKLM 'Software\\\\MyApp'
 ")
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I need to install some registry key for a NSIS installer. I'm working with CPACK and I found this command CPACK_PACKAGE_INSTALL_REGISTRY_KEY. There is not much doc on the Internet but I guess :

set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"MyReg\\\\MyKey" "${INSTALL_DIR}\\\\"
)

Or something not much different.

I also read this on an other topic:

list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
                InstallDirRegKey HKCU \"Software\\Test\" \"RegEntry\"
               ")

But I didn't understand why use this last command instead of the CPACK command.

Thank you for your help

Body:
I don't know anything about CPack but I guess CPACK_PACKAGE_INSTALL_REGISTRY_KEY also maps to InstallDirRegKey and cannot be used to write generic values to the registry.

Try something like this to insert raw NSIS instructions:

SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  WriteRegStr HKLM 'Software\\\\MyApp' 'MyValue' 'MyData'
  WriteRegDWORD HKLM 'Software\\\\MyApp' 'OtherValue' '4'
   ")
SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
  DeleteRegKey HKLM 'Software\\\\MyApp'
 ")


问:
Data type of Literals/Result of Arithmetic operations on Literals in Java
Can anybody please clarify the below:

```<code>byte a = 10 + 20; // b=30;
-------------
byte b=10,c=20;
byte a = b + c; //error. Casting required.
</code>```

What was the data type of result of addition in the first line before assigning it to 'a'? Do literals have a data type. Or do arithmetic result assign them one ?

答:
since b + c is an operation that can overflow you need to do</p>

```<code>byte a = (byte)(b + c);
</code>```

Body:
Can anybody please clarify the below:

byte a = 10 + 20; // b=30;
-------------
byte b=10,c=20;
byte a = b + c; //error. Casting required.

What was the data type of result of addition in the first line before assigning it to 'a'? Do literals have a data type. Or do arithmetic result assign them one ?

Body:
since b + c is an operation that can overflow you need to do

byte a = (byte)(b + c);


问:
C# notation understanding Select(int.Parse)
I found a little script that I understand fully. I've got a string with "1 -2 5 40" for example. It reads the input string, splits it into a temporary array. Then this array is parsed and each element is transformed into an integer. The whole thing is order to give the nearest integer to zero.

But what I don't understand is the notation Select(int.Parse). There is no lambda expression here and the method int.Parse isn't called with brackets. Same with the OrderBy(Math.Abs)

Thank you in advance =)

```<code>var temps = Console.ReadLine().Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);

var result = temps.Select(int.Parse)
.OrderBy(Math.Abs)
.ThenByDescending(x => x)
.FirstOrDefault();
</code>```

答:
int.Parse is a method group - what you're seeing is a method group conversion to a delegate. To see it without LINQ:

```<code>Func<string, int> parser = int.Parse;
int x = parser("10"); // x=10
</code>```

It's mostly equivalent to:

```<code>Func<string, int> parser = text => int.Parse(text);
</code>```

... although there are plenty of differences if you want to go into the details :)

Body:
I found a little script that I understand fully. I've got a string with "1 -2 5 40" for example. It reads the input string, splits it into a temporary array. Then this array is parsed and each element is transformed into an integer. The whole thing is order to give the nearest integer to zero.

But what I don't understand is the notation Select(int.Parse). There is no lambda expression here and the method int.Parse isn't called with brackets. Same with the OrderBy(Math.Abs)

Thank you in advance =)

var temps = Console.ReadLine().Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);

var result = temps.Select(int.Parse)
.OrderBy(Math.Abs)
.ThenByDescending(x => x)
.FirstOrDefault();

Body:
int.Parse is a method group - what you're seeing is a method group conversion to a delegate. To see it without LINQ:

Func<string, int> parser = int.Parse;
int x = parser("10"); // x=10

It's mostly equivalent to:

Func<string, int> parser = text => int.Parse(text);

... although there are plenty of differences if you want to go into the details :)


问:
Execute string as C#
I am checking conditions that could change and so would like to build them in a string and then run that string as C#.

```<code>//string conditionToCheck = user.Userdetail.Age > 18
string conditionToCheck = "user." + condition.Table + "." + condition.Column + " " + condition.Operator + " " + condition.Value;
if(conditionToCheck)
{
    ConditionsMet = true;
}
</code>```

Is there someway to convert conditionToCheck into C# ?

Background

I allow a user to create conditions by selecting a table and it's column and then assign and operator of > < == and a value.

Since a user can select any column of any table in the DB i need the code to check the conditions to handle anything.

答:
Yes, the best solution is probably to use the CodeDOM to dynamically compile C# code. After that you can use reflection to dynamically load and execute your compiled assembly and getting the results from the evaluation. I'm not sure if this is the best or the most elegant solution to your problem however.

You can find an example here

Title: Execute string as C#

Body:
I am checking conditions that could change and so would like to build them in a string and then run that string as C#.

//string conditionToCheck = user.Userdetail.Age > 18
string conditionToCheck = "user." + condition.Table + "." + condition.Column + " " + condition.Operator + " " + condition.Value;
if(conditionToCheck)
{
    ConditionsMet = true;
}

Is there someway to convert conditionToCheck into C# ?

Background

I allow a user to create conditions by selecting a table and it's column and then assign and operator of > < == and a value.

Since a user can select any column of any table in the DB i need the code to check the conditions to handle anything.


问:
ng-if showing element that has false expression
Why is this element showing? I've tried it on values from the component too.</p>

```<code><div ng-if="1 == 2">
  <p>File uploaded.</p>
</div>
</code>```

答:
Your spelling is wrong and you forgot the asterisk.

You need to do:

```<code><div *ngIf="1 == 2">
  <p>File uploaded.</p>
</div>
</code>```

Body:
Why is this element showing? I've tried it on values from the component too.

File uploaded.

Body:
Your spelling is wrong and you forgot the asterisk.

You need to do:

<div *ngIf="1 == 2">
  <p>File uploaded.</p>
</div>


答:
int.Parse is a method with signature string -> int (or actually, a method group, with different signatures. But the compiler can infer you need this one, because it is the only one that fits.

You could use this method as a parameter wherever you would supply a delegate parameter with the same signature.

Title: C# notation understanding Select(int.Parse)


答:
Select(int.Parse) is nearly equivalent to Select(x => int.Parse(x)).

The Select demands an Func<T, R>, which in this case is also the signature of int.Parse (it has a single parameter with a return value). It convers the method group to the matching delegate.

In this case Func<T, R> will map to Func<string, int>, so it matches the int Parse(string) signature.


问:
Dynamic font resize
This script resize text based on the text length. All works fine but the text does not resize up when deleting characters. what's missing? Hoping there is a script guru around to help me!

  $('#location').keypress(function() {

    var textLength = $(this).val().length;

    if (textLength < 20) {
      // Do noting
    } else if (textLength < 40) {
      $(this).css('font-size', '16px');
    } else if (textLength > 40) {
      $(this).css('font-size', '24px');
    }
    //console.log(textLength);
  }); ```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#location {
  font-size: 24px;
  outline: none;
  width: 200px;
  height: 30px;
  display: table-cell;
  vertical-align: middle;
  border: 1px solid #ccc;
}</code>```

<input type="text" id="location" placeholder="Placeholder Text" />```

答:
keypress will not fire on backspace, so change ot to keyup instaed

```<code>$('#location').keyup(function() {

    var textLength = $(this).val().length;

    if (textLength < 20) {
      // Do noting
    } else if (textLength < 40) {
      $(this).css('font-size', '16px');
    } else if (textLength > 40) {
      $(this).css('font-size', '24px');
    }
    //console.log(textLength);
  });
</code>```

Title: Dynamic font resize

Body:
This script resize text based on the text length. All works fine but the text does not resize up when deleting characters. what's missing? Hoping there is a script guru around to help me!

  $('#location').keypress(function() {

    var textLength = $(this).val().length;

    if (textLength < 20) {
      // Do noting
    } else if (textLength < 40) {
      $(this).css('font-size', '16px');
    } else if (textLength > 40) {
      $(this).css('font-size', '24px');
    }
    //console.log(textLength);
  });

#location {
  font-size: 24px;
  outline: none;
  width: 200px;
  height: 30px;
  display: table-cell;
  vertical-align: middle;
  border: 1px solid #ccc;
}

<input type="text" id="location" placeholder="Placeholder Text" />

Body:
keypress will not fire on backspace, so change ot to keyup instaed

$('#location').keyup(function() {

    var textLength = $(this).val().length;

    if (textLength < 20) {
      // Do noting
    } else if (textLength < 40) {
      $(this).css('font-size', '16px');
    } else if (textLength > 40) {
      $(this).css('font-size', '24px');
    }
    //console.log(textLength);
  });


问:
Should I use a Model Class for Creating SqlConnection Objects?
I am creating an Intranet Website using Active Directory and SQL Server 2008. I created an ASP.NET MVC project and am currently trying to establish a connection to the SQL Database, and since there are different database servers in my company, it would be practical for me to create a Model class that creates the connection strings.

My question is: is this malpractice? I know of Separation of concerns, so I am trying to do this here in order to have a better organization and clearer code but I also feel like this is too much for little functionality.

Let me demonstrate by using an example, this is a function used to create the connection string in the Model class SQLManager.cs :

```<code>SqlConnection connectWeb= new SqlConnection();//This would be in a constructor
public SqlConnection CreateWebConnection(string SQLServerWeb, string SQLWebDB)
{
    try
    {
        connectWeb.ConnectionString = "Data Source=" + SQLServerWeb + ";Initial Catalog=" + SQLWebDB
                                    + ";Integrated Security=SSPI";
        connectWeb.Open();
        return connectWeb;
    }catch(Exception e)
    {
            Console.WriteLine("Exception levée : \n\n" + e.ToString());
    }
    return null;
}
</code>```

It could be practical for me to use this function and just change the parameters when I need to change the connection string. For example I would have the following controller action method:

```<code>public ActionResult RoleBasedMenu()
{
    SQLManager sqlManager = new SQLManager();
    using(SqlConnection conn = sqlManager.CreateWebConnection("MyDataSource", "MyInitialCatalog"))
    {
        //SQL actions / queries here
    }
</code>```

Another thing that bothers me is opening the connection in a class and closing it in another.
I haven't seen this anywhere so I feel like I'm not doing it right, what do you think?

答:
You need to separate out the database connections from your controllers. In principal I take the approach of  UI --> Service --> DataLayer. Each controllers action can then call the appropriate service that talks to the correct datalayer which in turn connects to a specific database on whatever server.

I've done an example below which shows how this can be achieved. I've used the term "Role" as your post has a RoleBasedMenu action.

```<code>public class RoleController
{
    [HttpGet]
    public ActionResult RoleBasedMenu()
    {
        var myViewModel = new RoleViewModel();
        var myService = new RoleServiceLayer();
        var myRoleDetails = myService.GetRoleDetails();

        myViewModel.Details = myRoleDetails;

        return View("RoleBasedMenu", myViewModel);
    }
}

public class RoleViewModel
{
    public RoleDomainObject Details { get; set; }
}

public class RoleDomainObject
{
    public string Name { get; set; }
    //Other Properties here.
}

public class RoleServiceLayer
{
    public RoleDomainObject GetRoleDetails(int roleID)
    {
        var myRole = new RoleDomainObject();
        var dataLayer = new RoleDataLayer();
        var myRoleData = dataLayer.GetRoleDetails(roleID);

        var myDataRow = myRoleData.Tables[0].Rows[0];
        //Set role properties

        return myRole;
    }
}

public class RoleDataLayer
{
    public DataSet GetRoleDetails(int customerID)
    {
        //Connect to DB
        return new DataSet();
    }
}
</code>```

Ideally you would have the service and the datalayer in separate projects.

Hope that makes sense.

Body:
I am creating an Intranet Website using Active Directory and SQL Server 2008. I created an ASP.NET MVC project and am currently trying to establish a connection to the SQL Database, and since there are different database servers in my company, it would be practical for me to create a Model class that creates the connection strings.

My question is: is this malpractice? I know of Separation of concerns, so I am trying to do this here in order to have a better organization and clearer code but I also feel like this is too much for little functionality.

Let me demonstrate by using an example, this is a function used to create the connection string in the Model class SQLManager.cs :

SqlConnection connectWeb= new SqlConnection();//This would be in a constructor
public SqlConnection CreateWebConnection(string SQLServerWeb, string SQLWebDB)
{
    try
    {
        connectWeb.ConnectionString = "Data Source=" + SQLServerWeb + ";Initial Catalog=" + SQLWebDB
                                    + ";Integrated Security=SSPI";
        connectWeb.Open();
        return connectWeb;
    }catch(Exception e)
    {
            Console.WriteLine("Exception levée : \n\n" + e.ToString());
    }
    return null;
}

It could be practical for me to use this function and just change the parameters when I need to change the connection string. For example I would have the following controller action method:

public ActionResult RoleBasedMenu()
{
    SQLManager sqlManager = new SQLManager();
    using(SqlConnection conn = sqlManager.CreateWebConnection("MyDataSource", "MyInitialCatalog"))
    {
        //SQL actions / queries here
    }

Another thing that bothers me is opening the connection in a class and closing it in another.
I haven't seen this anywhere so I feel like I'm not doing it right, what do you think?

Body:
You need to separate out the database connections from your controllers. In principal I take the approach of  UI --> Service --> DataLayer. Each controllers action can then call the appropriate service that talks to the correct datalayer which in turn connects to a specific database on whatever server.

I've done an example below which shows how this can be achieved. I've used the term "Role" as your post has a RoleBasedMenu action.

public class RoleController
{
    [HttpGet]
    public ActionResult RoleBasedMenu()
    {
        var myViewModel = new RoleViewModel();
        var myService = new RoleServiceLayer();
        var myRoleDetails = myService.GetRoleDetails();

        myViewModel.Details = myRoleDetails;

        return View("RoleBasedMenu", myViewModel);
    }
}

public class RoleViewModel
{
    public RoleDomainObject Details { get; set; }
}

public class RoleDomainObject
{
    public string Name { get; set; }
    //Other Properties here.
}

public class RoleServiceLayer
{
    public RoleDomainObject GetRoleDetails(int roleID)
    {
        var myRole = new RoleDomainObject();
        var dataLayer = new RoleDataLayer();
        var myRoleData = dataLayer.GetRoleDetails(roleID);

        var myDataRow = myRoleData.Tables[0].Rows[0];
        //Set role properties

        return myRole;
    }
}

public class RoleDataLayer
{
    public DataSet GetRoleDetails(int customerID)
    {
        //Connect to DB
        return new DataSet();
    }
}

Ideally you would have the service and the datalayer in separate projects.

Hope that makes sense.


问:
Error when sending variable from AJAX to PHP
I'm generating table rows with data from a database.

Below is my code:

```<code><table class="table table-hover" id="dashEventTable">
    <thead>
        <tr>
            <th>Created at</th>
            <th>Seminar Name</th>
            <th>Quota</th>
            <th>Location</th>
            <th>Option</th>
            <th style="display:none"></th>
        </tr>
    </thead>
    <tbody script="javascript">
    <?php
    $one = 1;
    $Lihat="SELECT * FROM event where status = '$one'";
    $Tampil = mysqli_query( $db, $Lihat );
        while ( $hasil = mysqli_fetch_array ( $Tampil ) ) {
            $id_event = ( $hasil['id_event'] );
            $nama_event =  ( $hasil['nama_event'] );
            $lokasi =  ( $hasil['lokasi'] );
            $kuota  =  ( $hasil['kuota'] );
            $created_at =  ( $hasil['created_at'] );
            { ?>
        <tr>
            <td class="created_at"><?php echo date( 'Y-m-d h:i a', strtotime( $created_at ) ); ?></td>
            <td class="event_name"><?php echo "$nama_event"; ?></td>
            <td class="kuota"><?php echo "$kuota"; ?></td>
            <td class="lokasi"><?php echo "$lokasi"; ?></td>
            <td>
                <a class="btn btn-xs btn-danger btn_delete" data-toggle="modal" href="#deleteDashEvent"><i class="fa fa-trash"></i></a>
            </td>
            <td class="event_id" style="display:none"><?php echo "$id_event"; ?></td>
        </tr><?php }
        } ?>
    </tbody>
</table>
</code>```

Now when I click on the button inside the rows, it does two things, the first is going to this JavaScript function:

```<code>$( ".btn_delete" ).click(function() {
    var $row = $( this ).closest( "tr" ); // Find the row
    var event_id = $row.find( ".event_id" ).text();
    console.log( event_id );
    $.ajax({
        url: "contain_data.php",
        method: 'post',
        data: {
            'send': event_id
        },
        success: function() {
            alert( event_id );
        }
    });
});
</code>```

From the alert and console log, I saw that I got the correct ID for the event id of the row. The data will then be sent to the PHP file above, and inside that PHP is this:

```<code><?php
if ( isset( $_POST['send'] ) ) {
    $id_event = $_POST['send'];
} else {
    echo "The data has not been received!";
}
</code>```

The second thing it does is go to this div for the delete confirmation:

```<code><form action="admin_delete_event.php" enctype="multipart/form-data" id="event_delete_row" method="post" name="delete_event_row">
    <div class="modal fade" id="deleteDashEvent">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button aria-label="Close" class="close" data-dismiss="modal" type="button">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title">Delete Confirmation</h4>
                </div>
                <div class="modal-body">
                    <p>Are you sure want to delete this event?</p>
                </div>
                <div class="modal-footer">
                    <a class="btn btn-default" data-dismiss="modal" href="#">Batal</a>
                    <button class="btn btn-primary btn_confirm_delete" name="admin_delete_event" type="submit">DELETE</button>
                </div>
            </div>
        </div>
    </div>
</form>
</code>```

When the DELETE button is clicked, it will then go to this PHP file:

```<code><?php
session_start();
include( "config.php" );

if ( isset( $_POST['admin_delete_event'] ) ) {
    include( "contain_data.php" );

    $zero = 0;

    $delete_query = "UPDATE event, jadwal_acara, waktu_pendaftaran
        SET event.status = '$zero', jadwal_acara.status = '$zero', waktu_pendaftaran.status = '$zero'
        WHERE event.id_event = '$id_event'
        AND jadwal_acara.id_event = '$id_event'
        AND waktu_pendaftaran.id_event = '$id_event'";

    if ( mysqli_query( $db, $delete_query ) ) {
        $delete = "Data has been deleted";
        echo $delete;
    } else {
        echo "Error: " . $delete_query . "<br>" . mysqli_error( $db );
    }
} else {
    echo "The button is not detected!";
}
</code>```

The problem I am having is that I received this error when I click the delete confirmation button:

The data has not been received!

  Undefined variable: id_event in...

Which means that I fail in sending the data.

What am I doing wrong and how can I resolve it?

EDIT: after adding error handling to the php file, the value sent by the ajax is null instead of the id_event, do you guys know why?

答:
I got your error . Upto submit your first form through is correct when you go for delete conformation you miss that event_id and you just using that one in you "admin_delete_event.php" file that why it giving error

Undefined variable: id_event in...

Now just add an hidden input field in form and submit it then the event_id will be available to you.

```<code>    <form action="admin_delete_event.php" enctype="multipart/form-data" id="event_delete_row" method="post" name="delete_event_row">
        <div class="modal fade" id="deleteDashEvent">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button aria-label="Close" class="close" data-dismiss="modal" type="button">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h4 class="modal-title">Delete Confirmation</h4>
                    </div>
                    <div class="modal-body">
                        <p>Are you sure want to delete this event?</p>
                    </div>
                    <div class="modal-footer">
                        <a class="btn btn-default" data-dismiss="modal" href="#">Batal</a>
                        <button class="btn btn-primary btn_confirm_delete" name="admin_delete_event" type="submit">DELETE</button>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name='event_id' value='id' id='event'>
    </form>
</code>```

And just change this in your 1st Ajax

```<code>        $( ".btn_delete" ).click(function() {
        var $row = $( this ).closest( "tr" ); // Find the row
        var event_id = $row.find( ".event_id" ).text();
        console.log( event_id );
        $.ajax({
            url: "contain_data.php",
            method: 'post',
            data: {
                'send': event_id
            },
            success: function() {
                $('#event').val(event_id);
                alert( event_id );
            }
        });
    });
</code>```

Then it will work fine.

Body:
I'm generating table rows with data from a database.

Below is my code:

            Created at
            Seminar Name
            Quota
            Location
            Option

    <?php
    $one = 1;
    $Lihat="SELECT * FROM event where status = '$one'";
    $Tampil = mysqli_query( $db, $Lihat );
        while ( $hasil = mysqli_fetch_array ( $Tampil ) ) {
            $id_event = ( $hasil['id_event'] );
            $nama_event =  ( $hasil['nama_event'] );
            $lokasi =  ( $hasil['lokasi'] );
            $kuota  =  ( $hasil['kuota'] );
            $created_at =  ( $hasil['created_at'] );
            { ?>

            <?php echo date( 'Y-m-d h:i a', strtotime( $created_at ) ); ?>
            <?php echo "$nama_event"; ?>
            <?php echo "$kuota"; ?>
            <?php echo "$lokasi"; ?>

            <?php echo "$id_event"; ?>

<?php }
        } ?>

Now when I click on the button inside the rows, it does two things, the first is going to this JavaScript function:

$( ".btn_delete" ).click(function() {
    var $row = $( this ).closest( "tr" ); // Find the row
    var event_id = $row.find( ".event_id" ).text();
    console.log( event_id );
    $.ajax({
        url: "contain_data.php",
        method: 'post',
        data: {
            'send': event_id
        },
        success: function() {
            alert( event_id );
        }
    });
});

From the alert and console log, I saw that I got the correct ID for the event id of the row. The data will then be sent to the PHP file above, and inside that PHP is this:

<?php
if ( isset( $_POST['send'] ) ) {
    $id_event = $_POST['send'];
} else {
    echo "The data has not been received!";
}

The second thing it does is go to this div for the delete confirmation:

<form action="admin_delete_event.php" enctype="multipart/form-data" id="event_delete_row" method="post" name="delete_event_row">

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

Delete Confirmation

Are you sure want to delete this event?

                    Batal
                    <button class="btn btn-primary btn_confirm_delete" name="admin_delete_event" type="submit">DELETE</button>

</form>

When the DELETE button is clicked, it will then go to this PHP file:

<?php
session_start();
include( "config.php" );

if ( isset( $_POST['admin_delete_event'] ) ) {
    include( "contain_data.php" );

    $zero = 0;

    $delete_query = "UPDATE event, jadwal_acara, waktu_pendaftaran
        SET event.status = '$zero', jadwal_acara.status = '$zero', waktu_pendaftaran.status = '$zero'
        WHERE event.id_event = '$id_event'
        AND jadwal_acara.id_event = '$id_event'
        AND waktu_pendaftaran.id_event = '$id_event'";

    if ( mysqli_query( $db, $delete_query ) ) {
        $delete = "Data has been deleted";
        echo $delete;
    } else {
        echo "Error: " . $delete_query . "
" . mysqli_error( $db );
    }
} else {
    echo "The button is not detected!";
}

The problem I am having is that I received this error when I click the delete confirmation button:

The data has not been received!

  Undefined variable: id_event in...

Which means that I fail in sending the data.

What am I doing wrong and how can I resolve it?

EDIT: after adding error handling to the php file, the value sent by the ajax is null instead of the id_event, do you guys know why?

Body:
I got your error . Upto submit your first form through is correct when you go for delete conformation you miss that event_id and you just using that one in you "admin_delete_event.php" file that why it giving error

Undefined variable: id_event in...

Now just add an hidden input field in form and submit it then the event_id will be available to you.

    <form action="admin_delete_event.php" enctype="multipart/form-data" id="event_delete_row" method="post" name="delete_event_row">
        <div class="modal fade" id="deleteDashEvent">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button aria-label="Close" class="close" data-dismiss="modal" type="button">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">Delete Confirmation</h4>
                    </div>
                    <div class="modal-body">
                        <p>Are you sure want to delete this event?</p>
                    </div>
                    <div class="modal-footer">
                        <a class="btn btn-default" data-dismiss="modal" href="#">Batal</a>
                        <button class="btn btn-primary btn_confirm_delete" name="admin_delete_event" type="submit">DELETE</button>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name='event_id' value='id' id='event'>
    </form>

And just change this in your 1st Ajax

        $( ".btn_delete" ).click(function() {
        var $row = $( this ).closest( "tr" ); // Find the row
        var event_id = $row.find( ".event_id" ).text();
        console.log( event_id );
        $.ajax({
            url: "contain_data.php",
            method: 'post',
            data: {
                'send': event_id
            },
            success: function() {
                $('#event').val(event_id);
                alert( event_id );
            }
        });
    });

Then it will work fine.


答:
If its angular2 it should be *ngIf,

```<code><div *ngIf="1 == 2">
  <p>File uploaded.</p>
</div>
</code>```

Title: ng-if showing element that has false expression

Body:
If its angular2 it should be *ngIf,

<div *ngIf="1 == 2">
  <p>File uploaded.</p>
</div>


问:
Select the key:value pairs from a dictionary in Python
I have a Python Dict like as follows:

```<code>a = {"a":1,"b":2,"c":3,"f":4,"d":5}
</code>```

and I have a list like as follows:

```<code>b= ["b","c"]
</code>```

What I want to do is selecting the key:value pairs from the dict a with keys in b.
So the output should be a dictionary like:

```<code>out = {"b":2,"c":3}
</code>```

I could simply create another dictionary and update it using the key:value pair with iteration but I have RAM problems and the dictionary a is very large. b includes a few points so I thought popping from a does not work. What can I do to solve this issue?

Edit: Out is actually an update on a. So I will update the a as out.

Thanks :)

答:
If you truly want to create a new dictionary with the keys in your list, then you can use a dict comprehension.

```<code>a = {"a":1,"b":2,"c":3,"f":4,"d":5}
b = ["b", "c"]

out = {x: a[x] for x in b}
</code>```

This will fail by raising a KeyError if any of the elements of b are not actually keys in a.

Body:
I have a Python Dict like as follows:

a = {"a":1,"b":2,"c":3,"f":4,"d":5}

and I have a list like as follows:

b= ["b","c"]

What I want to do is selecting the key:value pairs from the dict a with keys in b.
So the output should be a dictionary like:

out = {"b":2,"c":3}

I could simply create another dictionary and update it using the key:value pair with iteration but I have RAM problems and the dictionary a is very large. b includes a few points so I thought popping from a does not work. What can I do to solve this issue?

Edit: Out is actually an update on a. So I will update the a as out.

Thanks :)

Body:
If you truly want to create a new dictionary with the keys in your list, then you can use a dict comprehension.

a = {"a":1,"b":2,"c":3,"f":4,"d":5}
b = ["b", "c"]

out = {x: a[x] for x in b}

This will fail by raising a KeyError if any of the elements of b are not actually keys in a.