问:
Android Multiple Screen
i have a problem with multiple screen in android.

after i read this web pages :

https://developer.android.com/guide/practices/screens_support.html
developer.android.com/training/multiscreen/screensizes.html

i tried to change my activity to a multiple screen layout with adding the smallest screen width layout directories :

layout-sw320dp

layout-sw320dp-land

layout-sw480dp

layout-sw480dp-land

layout-sw600dp

layout-sw600dp-land

layout-sw720dp

layout-sw720dp-land

my activity :

activity_main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/activity_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/background"
          tools:context="com.example.aref.calculator.MainActivity"
          android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lin"
    android:orientation="vertical">

    <EditText
        android:id="@+id/etInput"
        android:layout_height="163dp"
        android:background="@android:color/transparent"
        android:cursorVisible="false"
        android:gravity="end|center"
        android:hint="@string/zero"
        android:inputType="numberSigned"
        android:padding="16dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/darker_gray"
        android:textCursorDrawable="@null"
        android:textSize="50sp"
        android:layout_width="match_parent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMc"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:background="@drawable/btn_selector"
                android:text="@string/mc" />

            <Button
                android:id="@+id/btnMemory"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector"
                android:text="@string/nullMemory" />

            <Button
                android:id="@+id/btnSeven"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/seven" />

            <Button
                android:id="@+id/btnFour"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/four" />

            <Button
                android:id="@+id/btnOne"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/one" />

            <Button
                android:id="@+id/btnZero"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/zero" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mPlus" />

            <Button
                android:id="@+id/btnClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/clear" />

            <Button
                android:id="@+id/btnEight"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/eight" />

            <Button
                android:id="@+id/btnFive"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/five" />

            <Button
                android:id="@+id/btnTwo"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/two" />

            <Button
                android:id="@+id/btnPoint"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/point" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMMinus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mMinus" />

            <Button
                android:id="@+id/btnAllClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/AllClear" />

            <Button
                android:id="@+id/btnNine"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/nine" />

            <Button
                android:id="@+id/btnSix"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/six" />

            <Button
                android:id="@+id/btnThree"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/three" />

            <Button
                android:id="@+id/btnEqual"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/equal" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMr"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mr" />

            <Button
                android:id="@+id/btnMod"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mod" />

            <Button
                android:id="@+id/btnDiv"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/div" />

            <Button
                android:id="@+id/btnMul"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mul" />

            <Button
                android:id="@+id/btnPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/plus" />

            <Button
                android:id="@+id/btnMin"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/minus" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>
</code>```

for example my problem is in "layout-sw320dp" i design the layout for the nexus 5x when i change device for example to nexus 4 or nexus s layout becomes unfit

I M A G E :
http://s8.picofile.com/file/8299930926/564684.png

答: You're setting fixed width buttons.  That's never going to work well across devices.  Use another technique.  For example, if you want 4 equally sized buttons, put each row as a linear layout and assign them all 0dp width and a weight of 1, so they'll be made equally large.</p>

Title: Android Multiple Screen

Body:
i have a problem with multiple screen in android.

after i read this web pages :

https://developer.android.com/guide/practices/screens_support.html
developer.android.com/training/multiscreen/screensizes.html

i tried to change my activity to a multiple screen layout with adding the smallest screen width layout directories :

layout-sw320dp

layout-sw320dp-land

layout-sw480dp

layout-sw480dp-land

layout-sw600dp

layout-sw600dp-land

layout-sw720dp

layout-sw720dp-land

my activity :

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/activity_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/background"
          tools:context="com.example.aref.calculator.MainActivity"
          android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lin"
    android:orientation="vertical">

    <EditText
        android:id="@+id/etInput"
        android:layout_height="163dp"
        android:background="@android:color/transparent"
        android:cursorVisible="false"
        android:gravity="end|center"
        android:hint="@string/zero"
        android:inputType="numberSigned"
        android:padding="16dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/darker_gray"
        android:textCursorDrawable="@null"
        android:textSize="50sp"
        android:layout_width="match_parent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMc"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:background="@drawable/btn_selector"
                android:text="@string/mc" />

            <Button
                android:id="@+id/btnMemory"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector"
                android:text="@string/nullMemory" />

            <Button
                android:id="@+id/btnSeven"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/seven" />

            <Button
                android:id="@+id/btnFour"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/four" />

            <Button
                android:id="@+id/btnOne"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/one" />

            <Button
                android:id="@+id/btnZero"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/zero" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mPlus" />

            <Button
                android:id="@+id/btnClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/clear" />

            <Button
                android:id="@+id/btnEight"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/eight" />

            <Button
                android:id="@+id/btnFive"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/five" />

            <Button
                android:id="@+id/btnTwo"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/two" />

            <Button
                android:id="@+id/btnPoint"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/point" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMMinus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mMinus" />

            <Button
                android:id="@+id/btnAllClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/AllClear" />

            <Button
                android:id="@+id/btnNine"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/nine" />

            <Button
                android:id="@+id/btnSix"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/six" />

            <Button
                android:id="@+id/btnThree"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/three" />

            <Button
                android:id="@+id/btnEqual"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/equal" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/btnMr"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mr" />

            <Button
                android:id="@+id/btnMod"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mod" />

            <Button
                android:id="@+id/btnDiv"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/div" />

            <Button
                android:id="@+id/btnMul"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mul" />

            <Button
                android:id="@+id/btnPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/plus" />

            <Button
                android:id="@+id/btnMin"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/minus" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

for example my problem is in "layout-sw320dp" i design the layout for the nexus 5x when i change device for example to nexus 4 or nexus s layout becomes unfit

I M A G E :
http://s8.picofile.com/file/8299930926/564684.png


来源: stackexchange

问:
tensorflow two matrix elementwise multiply in axis = 0, (M,k) * (M,l) --> (M,k*l)
I have a two matrix, F(shape = (4000, 64)) and M(shape=(4000,9))
and want to have result that have shape = (4000,64*9)

i can think with for loop with below code(ideal)

```<code>result = np.zeros(4000,64*9)
ind = 0
for i in range(64):
    for j in range(9):
        result[:,ind]= tf.muliply(F[:,i]),M[:,j])
        ind += 1
</code>```

but i know For Loop is not support in tensorflow

Is there a function that performs the same function as above code?

edit)

I came up with an idea. F,M repeat to shape (4000,64*9) [liek repmat in MATLAB] and elementwise multiply.
Could you ever have any other ideas?

答:
You could use</p>

```<code>tf.reshape(M[:,tf.newaxis,:] * F[...,tf.newaxis], [4000,-1])
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have a two matrix, F(shape = (4000, 64)) and M(shape=(4000,9))
and want to have result that have shape = (4000,64*9)

i can think with for loop with below code(ideal)

result = np.zeros(4000,64*9)
ind = 0
for i in range(64):
    for j in range(9):
        result[:,ind]= tf.muliply(F[:,i]),M[:,j])
        ind += 1

but i know For Loop is not support in tensorflow

Is there a function that performs the same function as above code?

edit)

I came up with an idea. F,M repeat to shape (4000,64*9) [liek repmat in MATLAB] and elementwise multiply.
Could you ever have any other ideas?

Body:
You could use

tf.reshape(M[:,tf.newaxis,:] * F[...,tf.newaxis], [4000,-1])


问:
Can Hive deal with binary data?
Can Hive deal with unstructured data .
If we are having image file in oracle database and we have to run sqoopout to load that image from oracle to another source database and export as well in hive table.
Could you please help me on same how to handled that image file in hive?????</p>

答:
Your Oracle data is probably stored as BLOB.

In Hive it should be stored as BINARY.

Here is an Hortonworks article demonsrating sqoop import of oracle blob into hive

https://community.hortonworks.com/content/supportkb/49145/how-to-sqoop-import-oracle-blobclob-data-into-hive.html

Here is an example for processing of binary type using Hive UDF

https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBase64.java

Title: Can Hive deal with binary data?


问:
Does using lists of structs make sense in cocoa?
This question has spawned out of this one. Working with lists of structs in cocoa is not simple. Either use NSArray and encode/decode, or use a C type array and lose the commodities of NSArray. Structs are supposed to be simple, but when a list is needed, one would tend to build a class instead.

When does using lists of structs make sense in cocoa?

I know there are already many questions regarding structs vs classes, and I've read users argue that it's the same answer for every language, but at least cocoa should have its own specific answers to this, if only because of KVC or bindings (as Peter suggested on the first question).

答:
It is convenient and useful at times to use structs, especially when you have to drop down to C, such as when working with an existing library or doing system level stuff.  Sometimes you just want a compact data structure without the overhead of a class.  If you need many instances of such structs, it can make a real impact on performance and memory footprint.

Another way to do an array of structs is to use the NSPointerArray class.  It takes a bit more thought to set up but it works pretty much just like an NSArray after that and you don't have to bother with boxing/unboxing or wrapping in a class so accessing the data is more convenient, and it doesn't take up the extra memory of a class.

```<code>NSPointerFunctions *pf = [[NSPointerFunctions alloc] initWithOptions:NSPointerFunctionsMallocMemory |
                          NSPointerFunctionsStructPersonality |
                          NSPointerFunctionsCopyIn];
pf.sizeFunction = keventSizeFunction;
self.pending = [[NSPointerArray alloc] initWithPointerFunctions:pf];
</code>```

OwnerDisplayName: Steph Thirion

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: Steph Thirion

Body:
It is convenient and useful at times to use structs, especially when you have to drop down to C, such as when working with an existing library or doing system level stuff.  Sometimes you just want a compact data structure without the overhead of a class.  If you need many instances of such structs, it can make a real impact on performance and memory footprint.

Another way to do an array of structs is to use the NSPointerArray class.  It takes a bit more thought to set up but it works pretty much just like an NSArray after that and you don't have to bother with boxing/unboxing or wrapping in a class so accessing the data is more convenient, and it doesn't take up the extra memory of a class.

NSPointerFunctions *pf = [[NSPointerFunctions alloc] initWithOptions:NSPointerFunctionsMallocMemory |
                          NSPointerFunctionsStructPersonality |
                          NSPointerFunctionsCopyIn];
pf.sizeFunction = keventSizeFunction;
self.pending = [[NSPointerArray alloc] initWithPointerFunctions:pf];

OwnerDisplayName: s-bug


问:
Exception in property when setting a binary value
I have the following method which gives me a stackoverflow exception on setting a value. I can't step into it and debug it application just crashes few seconds later. Here is the code

```<code>public byte[] ImageTIFF
{
    get
    {
        try
        {
            string filePath = ImageTIFFDir + ImageId + ".TIFF";

            if (File.Exists(filePath))
            {
                return File.ReadAllBytes(ImageTIFFDir + ImageCollectionId + ".TIFF");
            }
            else
            {
                return null;
            }
        }
        catch (Exception e)
        {
            Logger.log("Can't read TIFF image from file.", e);
            throw;
        }
    }
    set
    {
        try
        {
            ImageTIFF = value;
        }
        catch (Exception e)
        {
            Logger.log("Can't set image TIFF.", e);
            throw;
        }

    }
}
</code>```

This gets called during an export and it fails on a first call:

```<code>someImage.ImageTIFF = File.ReadAllBytes(imageName);
</code>```

答:
Here you try to set value to the property you are already in.

```<code>try
{
    ImageTIFF = value;
}
</code>```

You need to have class member behind that property. Something like

```<code>byte[] _imageTIFF
</code>```

and set it

```<code>set
{
    try
    {
        _imageTIFF = value;
    }
    catch (Exception e)
    {
        Logger.log("Can't set image TIFF.", e);
        throw;
    }
}
</code>```

Body:
I have the following method which gives me a stackoverflow exception on setting a value. I can't step into it and debug it application just crashes few seconds later. Here is the code

public byte[] ImageTIFF
{
    get
    {
        try
        {
            string filePath = ImageTIFFDir + ImageId + ".TIFF";

            if (File.Exists(filePath))
            {
                return File.ReadAllBytes(ImageTIFFDir + ImageCollectionId + ".TIFF");
            }
            else
            {
                return null;
            }
        }
        catch (Exception e)
        {
            Logger.log("Can't read TIFF image from file.", e);
            throw;
        }
    }
    set
    {
        try
        {
            ImageTIFF = value;
        }
        catch (Exception e)
        {
            Logger.log("Can't set image TIFF.", e);
            throw;
        }

    }
}

This gets called during an export and it fails on a first call:

someImage.ImageTIFF = File.ReadAllBytes(imageName);

Body:
Here you try to set value to the property you are already in.

try
{
    ImageTIFF = value;
}

You need to have class member behind that property. Something like

byte[] _imageTIFF

and set it

set
{
    try
    {
        _imageTIFF = value;
    }
    catch (Exception e)
    {
        Logger.log("Can't set image TIFF.", e);
        throw;
    }
}


问:
How to show Notification in cordova using th plugin cordova-plugin-background-mode?
I tried to install plugin :

cordova-plugin-local-notifications

but showed already installed.

Then I tried

```<code>cordova.plugins.notification.local.schedule({
    id: 1,
    title:"title",
    text: "Single Notification"
});
</code>```

it results in

function local not found error
  then I tried

```<code>cordova.plugins.localNotifications.schedule({
   id: 1,
   text: "Single Notification"
});
</code>```

It result in

```<code>function schedule not found error
</code>```

Someone please help.

答:
Make sure to reference cordova.js in your HTML file.

```<code><script src="cordova.js"></script>
</code>```

Once it's referenced you should be able to call the function.

Body:
I tried to install plugin :

cordova-plugin-local-notifications

but showed already installed.

Then I tried

cordova.plugins.notification.local.schedule({
    id: 1,
    title:"title",
    text: "Single Notification"
});

it results in

function local not found error
  then I tried

cordova.plugins.localNotifications.schedule({
   id: 1,
   text: "Single Notification"
});

It result in

function schedule not found error

Someone please help.

Body:
Make sure to reference cordova.js in your HTML file.

<script src="cordova.js"></script>

Once it's referenced you should be able to call the function.


问:
Echoing a Product of Two Variables in PHP
I have the following code:

```<code>    $sel_referrals1="SELECT SUM(amount) as da_sum FROM topup WHERE user_id IN(SELECT t1.referree
FROM referrals AS t1
LEFT JOIN referrals AS t2 ON t2.referrer = t1.referree
LEFT JOIN referrals AS t3 ON t3.referrer = t2.referree
LEFT JOIN referrals AS t4 ON t4.referrer = t3.referree
LEFT JOIN referrals AS t5 ON t5.referrer = t4.referree
LEFT JOIN referrals AS t6 ON t6.referrer = t5.referree
LEFT JOIN referrals AS t7 ON t7.referrer = t6.referree
LEFT JOIN referrals AS t8 ON t8.referrer = t7.referree
LEFT JOIN referrals AS t9 ON t9.referrer = t8.referree
LEFT JOIN referrals AS t10 ON t10.referrer = t9.referree
LEFT JOIN referrals AS t11 ON t11.referrer = t10.referree
WHERE t1.referrer = '{$_SESSION['user']}')
AND YEAR(date_time) = YEAR(CURRENT_DATE())
AND MONTH(date_time) = MONTH(CURRENT_DATE())";

    $selected1=mysqli_query($conn,$sel_referrals1);
    $sel_level1_array=mysqli_fetch_row($selected1);
    $level1=number_format($sel_level1_array[0],2);
</code>```

$level1 evaluates as 1260.00.I have another variable $rate1 which is set as follows: $rate1=0.02.I need to multiply $level1 with $rate1. But, when code executes the   multiplication of $level1 * $rate1, the result yields 0.02.

My expected result is 25.20. What am I doing wrong?

答:
Everything is fine.

try this:

```<code><?php
 $rate1=0.02;
 $level1=1260;
 echo "Level1 = ".$level1.'<br>';
 echo "Rate1 = ".$rate1.'<br>';
 echo "Format Number using variables = ".number_format($level1 * $rate1,2).'<br>';
 echo "Format Number using numbers = ".number_format(1260 * 0.02,2);
?>
</code>```

Body:
I have the following code:

    $sel_referrals1="SELECT SUM(amount) as da_sum FROM topup WHERE user_id IN(SELECT t1.referree
FROM referrals AS t1
LEFT JOIN referrals AS t2 ON t2.referrer = t1.referree
LEFT JOIN referrals AS t3 ON t3.referrer = t2.referree
LEFT JOIN referrals AS t4 ON t4.referrer = t3.referree
LEFT JOIN referrals AS t5 ON t5.referrer = t4.referree
LEFT JOIN referrals AS t6 ON t6.referrer = t5.referree
LEFT JOIN referrals AS t7 ON t7.referrer = t6.referree
LEFT JOIN referrals AS t8 ON t8.referrer = t7.referree
LEFT JOIN referrals AS t9 ON t9.referrer = t8.referree
LEFT JOIN referrals AS t10 ON t10.referrer = t9.referree
LEFT JOIN referrals AS t11 ON t11.referrer = t10.referree
WHERE t1.referrer = '{$_SESSION['user']}')
AND YEAR(date_time) = YEAR(CURRENT_DATE())
AND MONTH(date_time) = MONTH(CURRENT_DATE())";

    $selected1=mysqli_query($conn,$sel_referrals1);
    $sel_level1_array=mysqli_fetch_row($selected1);
    $level1=number_format($sel_level1_array[0],2);

$level1 evaluates as 1260.00.I have another variable $rate1 which is set as follows: $rate1=0.02.I need to multiply $level1 with $rate1. But, when code executes the   multiplication of $level1 * $rate1, the result yields 0.02.

My expected result is 25.20. What am I doing wrong?

Body:
Everything is fine.

try this:

<?php
 $rate1=0.02;
 $level1=1260;
 echo "Level1 = ".$level1.'<br>';
 echo "Rate1 = ".$rate1.'<br>';
 echo "Format Number using variables = ".number_format($level1 * $rate1,2).'<br>';
 echo "Format Number using numbers = ".number_format(1260 * 0.02,2);
?>


问:
How to use home component data in other component?
Below is my code, how to use (this.categoryType) in other component

```<code>getCategoryDetails(){
return this.http.get('ip/ramu/api/api/…')
.map((res:Response) => res.json());
}
</code>```

Above code I am using in webservice.ts

```<code>ngOnInit() { this.wsp.getCategoryDetails().subscribe(data => {
this.categoryType = data; });
}
</code>```

Above code I have used in home.ts, but I want use this response in other component.

答:
Use a service to save the category. And then you can use the same service to get the categoryType whenever you want it.

```<code>import { Injectable } from '@angular/core';
@Injectable()
export class AppMessageQueuService {

    categoryType: string;
    constructor() {

    }
    saveCateogry(cat:any){
        this.categoryType= cat;
    }
    retrieveCategory(){
        return this.categoryType;
    }

}
</code>```

Then you can inject this Service into both the components and save it from the first component like,

```<code>this.appMsgService.saveCateogry(yourcategory);
</code>```

then retrieve in the second component as,

```<code>this.appMsgService.retrieveCategory();
</code>```

Body:
Below is my code, how to use (this.categoryType) in other component

getCategoryDetails(){
return this.http.get('ip/ramu/api/api/…')
.map((res:Response) => res.json());
}

Above code I am using in webservice.ts

ngOnInit() { this.wsp.getCategoryDetails().subscribe(data => {
this.categoryType = data; });
}

Above code I have used in home.ts, but I want use this response in other component.

Body:
Use a service to save the category. And then you can use the same service to get the categoryType whenever you want it.

import { Injectable } from '@angular/core';
@Injectable()
export class AppMessageQueuService {

    categoryType: string;
    constructor() {

    }
    saveCateogry(cat:any){
        this.categoryType= cat;
    }
    retrieveCategory(){
        return this.categoryType;
    }

}

Then you can inject this Service into both the components and save it from the first component like,

this.appMsgService.saveCateogry(yourcategory);

then retrieve in the second component as,

this.appMsgService.retrieveCategory();


问:
Can I delay an alert in jquery?
I want an alert to come up after so many seconds rather than instantly, is there a way I can do this in jquery? So far I've tried the following but I believe delay is specifically for animations. Thanks.</p>

```<code>alert ("Death").delay(1000);
</code>```

答:
Yeah apart from setting timeout. you can as well append the alert or prompt

```<code>setTimeout(function() {
var addmust = prompt("Please if you dont mind may we Know who you are");
$("#addname").append(addmust);
}, 6000);
</code>```

html code

```<code><p>Please rate us <span id="addname"></span>
</code>```

Title: Can I delay an alert in jquery?

Body:
I want an alert to come up after so many seconds rather than instantly, is there a way I can do this in jquery? So far I've tried the following but I believe delay is specifically for animations. Thanks.

alert ("Death").delay(1000);

Body:
Yeah apart from setting timeout. you can as well append the alert or prompt

setTimeout(function() {
var addmust = prompt("Please if you dont mind may we Know who you are");
$("#addname").append(addmust);
}, 6000);

html code

<p>Please rate us <span id="addname"></span>


问:
Action creator in not dispatching an action
After several hrs of trying I have to come here...

The problem I am facing is that I am not able to dispatch my action, though I am successfully able to call my action creator.

My Action Creator in loginActions file

```<code>const changeForm = (newState) => (dispatch) => {
    dispatch({ type: actionTypes.CHANGE_FORM, newState });
};
</code>```

In my component, I have imported loginActions

```<code>function mapDispatchToProps(dispatch) {
  return {
    login: loginActions.loginCheck,
    changeForm: loginActions.changeForm
  };
}

export default connect(mapStateToProps,mapDispatchToProps)(LoginPage);
</code>```

and I passing this in my form component like this

const changeForm = this.props.changeForm;

```<code><Form data={data}
      changeForm={changeForm}
      onSubmit={onSubmit}
      btnText={"Login"}
      currentlySending={currentlySending}/>
</code>```

Inside my  component, I am doing something like this with newState

this.props.changeForm(newState);

But this stuff in not dispatching the action. please help. Let me know if you want me to the additional info. Thanks in advance.

答:
You should change mapDispatchToProps so that you use dispatch there.

```<code>function mapDispatchToProps(dispatch) {
  return {
    changeForm: newState => dispatch(loginActions.changeForm(newState))
  }
}
</code>```

And the action creator doesn't need dispatch.

```<code>const changeForm = newState => (
    { type: actionTypes.CHANGE_FORM, payload: newState }
)
</code>```

Body:
After several hrs of trying I have to come here...

The problem I am facing is that I am not able to dispatch my action, though I am successfully able to call my action creator.

My Action Creator in loginActions file

const changeForm = (newState) => (dispatch) => {
    dispatch({ type: actionTypes.CHANGE_FORM, newState });
};

In my component, I have imported loginActions

function mapDispatchToProps(dispatch) {
  return {
    login: loginActions.loginCheck,
    changeForm: loginActions.changeForm
  };
}

export default connect(mapStateToProps,mapDispatchToProps)(LoginPage);

and I passing this in my form component like this

const changeForm = this.props.changeForm;

<Form data={data}
      changeForm={changeForm}
      onSubmit={onSubmit}
      btnText={"Login"}
      currentlySending={currentlySending}/>

Inside my  component, I am doing something like this with newState

this.props.changeForm(newState);

But this stuff in not dispatching the action. please help. Let me know if you want me to the additional info. Thanks in advance.

Body:
You should change mapDispatchToProps so that you use dispatch there.

function mapDispatchToProps(dispatch) {
  return {
    changeForm: newState => dispatch(loginActions.changeForm(newState))
  }
}

And the action creator doesn't need dispatch.

const changeForm = newState => (
    { type: actionTypes.CHANGE_FORM, payload: newState }
)


问:
Unable to import jar in scala console to run spark programe
I am using scala 2.11.8, when i am using require to import jars i am getting below issue.</p>

```<code>scala> util.Properties.versionNumberString
res7: String = 2.11.8

scala> :require /home/muralee1857/.ivy2/cache/com.google.code.gson/gson/jars/gson-2.4.jar
The path '/home/muralee1857/.ivy2/cache/com.google.code.gson/gson/jars/gson-2.4.jar' cannot be loaded, because existing classpath entries conflict.
</code>```

答:
The error message:

```<code>x cannot be loaded, because existing classpath entries conflict.
</code>```

signifies that either you have already loaded the jar or there is another package loaded which is conflicting with the names.

Try running the following in the spark console:

```<code>import com.google.gson.Gson
import scala.collection.JavaConversions._

val mapJson = "{ 'a': 'b', 'c': 'd' }"
val map = new Gson().fromJson(mapJson, classOf[java.util.Map[String, String]])
</code>```

If you get import errors this means you don't have the gson package loaded.

Body:
I am using scala 2.11.8, when i am using require to import jars i am getting below issue.

scala> util.Properties.versionNumberString
res7: String = 2.11.8

scala> :require /home/muralee1857/.ivy2/cache/com.google.code.gson/gson/jars/gson-2.4.jar
The path '/home/muralee1857/.ivy2/cache/com.google.code.gson/gson/jars/gson-2.4.jar' cannot be loaded, because existing classpath entries conflict.

Body:
The error message:

x cannot be loaded, because existing classpath entries conflict.

signifies that either you have already loaded the jar or there is another package loaded which is conflicting with the names.

Try running the following in the spark console:

import com.google.gson.Gson
import scala.collection.JavaConversions._

val mapJson = "{ 'a': 'b', 'c': 'd' }"
val map = new Gson().fromJson(mapJson, classOf[java.util.Map[String, String]])

If you get import errors this means you don't have the gson package loaded.


问:
after_or_equal validation does not work in laravel 5.2
I want to compare start_date with end_date ,
and end_date should be equal or greater then start_date,
i am using after_or_equal validation.</p>

```<code>return Validator::make($data, [
      'start_date' => 'required',
      'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date'
]);

after_or_create validation of laravel5.2 return error like this.
Method [validateAfterOrEqual] does not exist.
</code>```

答:
you need to upgrade your version to 5.4 to use after_or_equal

https://laravel.com/docs/5.4/validation#rule-after-or-equal

Note : after_or_equal is available from version laravel 5.3

Body:
I want to compare start_date with end_date ,
and end_date should be equal or greater then start_date,
i am using after_or_equal validation.

return Validator::make($data, [
      'start_date' => 'required',
      'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date'
]);

after_or_create validation of laravel5.2 return error like this.
Method [validateAfterOrEqual] does not exist.


问:
Output three colums from my mysql database php
I'm a beginner in php and i'd like to output 3 fields from my database to my website which included a bloc image,text and name. using a foreach i can only get 2 out of the three.

```<code><table border="2px">
    <tr>
        <th> Brand</th>
        <th> Images</th>
        <th> Details</th>
    </tr>

    <?php
    $tex   = [];
    $query = mysqli_query($conn, "SELECT * FROM upload");
    while ($row = mysqli_fetch_assoc($query)) {
        $images[] = $row['image'];
        $br[]     = $row['name'];
        $det[]    = $row['text'];
    }
    foreach (array_combine($det, $images) as $text => $image) {
        echo "<tr><td>";
        echo $name;
        echo "</td>";
        echo "<td>";
        echo '<img src="data:image/jpeg;base64,'.base64_encode($image).'"/>';
        echo "<td>";
        echo $text;
        echo "</td>";
        echo "</td></tr>";
    }
    ?>
</table>
</code>```

that is a snippet of my code where images and text is outputted on the screen and receive and undefined variable in error in line 39 which would be echo $name;. what should i put in the foreach statement to get it to output all three?

```<code>$images[] = $row['image'];
$br[]     = $row['name'];
$det[]    = $row['text'];
</code>```

can someone explain these to me as i have an idea what it is doing but i want to be 100.

答:
This would work:

```<code>while ($row = mysqli_fetch_assoc($query)) {
    $images[] = $row['image'];
    $br[]     = $row['name'];
    $det[]    = $row['text'];
}
foreach ($images as $idx => $image) {
    echo "<tr><td>";
    echo $br[$idx];
    echo "</td>";
    echo "<td>";
    echo '<img src="data:image/jpeg;base64,'.base64_encode($image).'"/>';
    echo "<td>";
    echo $det[$idx];
    echo "</td>";
    echo "</td></tr>";
}
</code>```

You are combining only text and image. That way you would not know which name is the corresponding one. My loop solves this by using the index ($idx) for that. All arrays have the same size, so this works.

Body:
I'm a beginner in php and i'd like to output 3 fields from my database to my website which included a bloc image,text and name. using a foreach i can only get 2 out of the three.

         Brand
         Images
         Details

    <?php
    $tex   = [];
    $query = mysqli_query($conn, "SELECT * FROM upload");
    while ($row = mysqli_fetch_assoc($query)) {
        $images[] = $row['image'];
        $br[]     = $row['name'];
        $det[]    = $row['text'];
    }
    foreach (array_combine($det, $images) as $text => $image) {
        echo "
";
        echo $name;
        echo "	";
        echo "";
        echo '';
        echo "";
        echo $text;
        echo "	";
        echo "
";
    }
    ?>

that is a snippet of my code where images and text is outputted on the screen and receive and undefined variable in error in line 39 which would be echo $name;. what should i put in the foreach statement to get it to output all three?

$images[] = $row['image'];
$br[]     = $row['name'];
$det[]    = $row['text'];

can someone explain these to me as i have an idea what it is doing but i want to be 100.

Body:
This would work:

while ($row = mysqli_fetch_assoc($query)) {
    $images[] = $row['image'];
    $br[]     = $row['name'];
    $det[]    = $row['text'];
}
foreach ($images as $idx => $image) {
    echo "<tr><td>";
    echo $br[$idx];
    echo "</td>";
    echo "<td>";
    echo '<img src="data:image/jpeg;base64,'.base64_encode($image).'"/>';
    echo "<td>";
    echo $det[$idx];
    echo "</td>";
    echo "</td></tr>";
}

You are combining only text and image. That way you would not know which name is the corresponding one. My loop solves this by using the index ($idx) for that. All arrays have the same size, so this works.


问:
Problem aligning divs next to each other?
I want this design:

```<code>DIV1: auto-size DIV2: 160px
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
</code>```

How do I solve this problem? I've tried stuff like floating left & right, but I just can't get them on the same line.

I want the div 2 to always be there, and the div1 to have a max-width of 40em, but resize to allow the div 2 to show at all times if its necessary.

My code:

```<code><style="text/css">
#mainbulk {
    padding: 1.5em 2% 1.5em .5em;
}
#ads {
    width: 7.5em;
    float: left;
    display: table-cell;
padding: 0 0 0 2em;
}
#textcontent {
    width: 70%;
    float: left;
    display: table-cell;
}
</style>
</code>```

and

```<code><div id="mainbulk">
    <div id="textcontent">
        <p>This is the most amazing site in the world. It has a very nice design, and is perfect for everything. If there's something that this site can't do, then nothing can do it, but I'd suggest to try all of this site's features before complaining.</p>
    </div>
    <div id="ads" align="right">
    ads would, hypothetically, be placed here if this were actually an actual website.
    </div>
</div>
</code>```

I'm encountering this problem:

http://www.screencast-o-matic.com/watch/c6lrXsXyQ

答:
Try the following. ids are used for unique content and should be used once only per page.
Also tables are still worth considering in some circumstances. Using borders on your divs while you are working on the layout will also help (red and green borders below).</p>

```<code><html>
<head>
<style type="text/css">

.textcontent {
    float: left;
    border: 1px solid red;
    width: 700px;
    margin-bottom: 4px;
    }

.ads {
    float: left;
    width: 120px;
    border: 1px solid green;
    }

.textcontent:before {
    clear: left;
    }

</style>

</head>
<body>
<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

</body>
</html>
</code>```

Body:
I want this design:

DIV1: auto-size DIV2: 160px
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo
divnumberonediv divtwo

How do I solve this problem? I've tried stuff like floating left & right, but I just can't get them on the same line.

I want the div 2 to always be there, and the div1 to have a max-width of 40em, but resize to allow the div 2 to show at all times if its necessary.

My code:

and

This is the most amazing site in the world. It has a very nice design, and is perfect for everything. If there's something that this site can't do, then nothing can do it, but I'd suggest to try all of this site's features before complaining.

    ads would, hypothetically, be placed here if this were actually an actual website.

I'm encountering this problem:

http://www.screencast-o-matic.com/watch/c6lrXsXyQ

Body:
Try the following. ids are used for unique content and should be used once only per page.
Also tables are still worth considering in some circumstances. Using borders on your divs while you are working on the layout will also help (red and green borders below).

<html>
<head>
<style type="text/css">

.textcontent {
    float: left;
    border: 1px solid red;
    width: 700px;
    margin-bottom: 4px;
    }

.ads {
    float: left;
    width: 120px;
    border: 1px solid green;
    }

.textcontent:before {
    clear: left;
    }

</style>

</head>
<body>
<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

<div class="textcontent">textcontent div content</div>
<div class="ads">ads div content</div>

</body>
</html>


问:
How to calculate weight to minimize variance?
given several vectors:

```<code>x1 = [3 4 6]
x2 = [2 8 1]
x3 = [5 5 4]
x4 = [6 2 1]
</code>```

I wanna find weight w1, w2, w3 to each item, and get the weighted sum of each vector: yi = w1*i1 + w2*i2 + w3*i3. for example, y1 = 3*w1 + 4*w2 + 6*w3
to make the variance of these values(y1, y2, y3, y4) to be minimized.

notice: w1, w2, w3 should > 0, and w1 + w2 + w3 = 1

I don't know what kind of problems it should be... and how to solve it in python or matlab?

答:
```<code>w = [5, 6, 7]
x1 = [3, 4, 6]
x2 = [2, 8, 1]
x3 = [5, 5, 4]
y1, y2, y3 = 0, 0, 0
for index, i in enumerate(w):
    y1 = y1 + i * x1[index]
    y2 = y2 + i * x2[index]
    y3 = y3 + i * x3[index]
print(min(y1, y2, y3))
</code>```

I think I maybe get the purpose of your problem.But if you want to find the smallest value, I hope this can help you.
I just make the values fixed, you can make it to be the def when you see this is one way to solve your question.

Body:
given several vectors:

x1 = [3 4 6]
x2 = [2 8 1]
x3 = [5 5 4]
x4 = [6 2 1]

I wanna find weight w1, w2, w3 to each item, and get the weighted sum of each vector: yi = w1*i1 + w2*i2 + w3*i3. for example, y1 = 3*w1 + 4*w2 + 6*w3
to make the variance of these values(y1, y2, y3, y4) to be minimized.

notice: w1, w2, w3 should > 0, and w1 + w2 + w3 = 1

I don't know what kind of problems it should be... and how to solve it in python or matlab?

Body:
w = [5, 6, 7]
x1 = [3, 4, 6]
x2 = [2, 8, 1]
x3 = [5, 5, 4]
y1, y2, y3 = 0, 0, 0
for index, i in enumerate(w):
    y1 = y1 + i * x1[index]
    y2 = y2 + i * x2[index]
    y3 = y3 + i * x3[index]
print(min(y1, y2, y3))

I think I maybe get the purpose of your problem.But if you want to find the smallest value, I hope this can help you.
I just make the values fixed, you can make it to be the def when you see this is one way to solve your question.


问:
incorrect syntax near where but all the brackets are in the right places
```<code>SELECT
    [GMI Division#], [GMI Division],
    [Type_Mapping],
    SUM(Delv_EQC_Fctr) AS Delv_EQC_Fctr,
    SUM(Cuts_EQC_Fctr) AS Cuts_EQC_Fctr
FROM
    (SELECT
         [GMI Division#], [GMI Division],
         [Type_Mapping], [Base Product#],
         SUM([BUoM_Delivery Quantity]) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Delv_EQC_Fctr,
         (SUM([BUoM_GMI Order Cut Total]) + SUM([BUoM_GMI Delivery Cut Total])) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Cuts_EQC_Fctr
     FROM
         [dbo].[CF_Weekly_Casefill_Final_TY]
     LEFT JOIN
         [dbo].[CF_VEDW_PRD_MATL_DIM_N] ON [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#] = CAST([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] AS BIGINT)
     GROUP BY
         [GMI Division#], [GMI Division], [Type_Mapping], [Base Product#],
         [EQC_FCTR], [BUoM_Delivery Quantity], [BUoM_GMI Order Cut Total], [BUoM_GMI Delivery Cut Total])
WHERE
    (([GMI Division#] IN (01, 03, 12, 16, 50)
      AND [Distribution channel] IN ('RT', 'ML')) OR
     ([GMI Division#] IN (08) AND [Distribution channel] IN ('FS')))
    AND RIGHT([Fiscal Year/Period], 4) IN (2018)
GROUP BY
    [GMI Division#], [GMI Division], [Type_Mapping], [EQC_FCTR]
</code>```

This throws an error "incorrect syntax near where"

答:
Writing your code is the first part. You need to format it properly. Without that formatting, it is hard to read you.

This is a rewrite version of your query

```<code>WITH temp1 AS
(
  SELECT [GMI Division#],
  [GMI Division],[Type_Mapping],
  [Base Product#],
  SUM([BUoM_Delivery Quantity])*([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Delv_EQC_Fctr,
  (SUM([BUoM_GMI Order Cut Total]) + SUM([BUoM_GMI Delivery Cut Total])) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Cuts_EQC_Fctr
  FROM [dbo].[CF_Weekly_Casefill_Final_TY] LEFT JOIN [dbo].[CF_VEDW_PRD_MATL_DIM_N] ON
  [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#]=cast([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] as bigint)
  GROUP BY
  [GMI Division#],
  [GMI Division],
  [Type_Mapping],
  [Base Product#],
  [EQC_FCTR],
  [BUoM_Delivery Quantity],
  [BUoM_GMI Order Cut Total],
  [BUoM_GMI Delivery Cut Total]
)
SELECT [GMI Division#],[GMI Division],
        [Type_Mapping],Sum(Delv_EQC_Fctr) AS Delv_EQC_Fctr,
        Sum(Cuts_EQC_Fctr) AS Cuts_EQC_Fctr
FROM temp1
WHERE (([GMI Division#] in (01,03,12,16,50) and
([Distribution channel] IN ('RT','ML')) OR ([GMI Division#] in (08))
AND [Distribution channel] IN ('FS')))
AND  right([Fiscal Year/Period],4) IN (2018)
GROUP BY [GMI Division#],
        [GMI Division],
        [Type_Mapping],
        [EQC_FCTR]
</code>```

I'm not sure where lies the problem with your WHERE clause.

To find the issue, I would operate that way.

Try to start with only one condition and see how it goes

If condition one is ok, add another one and etc

You have 4 conditions, it should be fast.

Best of luck

Update

There are website where you can format your code like this one -> http://www.sql-format.com/

Body:
SELECT
    [GMI Division#], [GMI Division],
    [Type_Mapping],
    SUM(Delv_EQC_Fctr) AS Delv_EQC_Fctr,
    SUM(Cuts_EQC_Fctr) AS Cuts_EQC_Fctr
FROM
    (SELECT
         [GMI Division#], [GMI Division],
         [Type_Mapping], [Base Product#],
         SUM([BUoM_Delivery Quantity]) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Delv_EQC_Fctr,
         (SUM([BUoM_GMI Order Cut Total]) + SUM([BUoM_GMI Delivery Cut Total])) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Cuts_EQC_Fctr
     FROM
         [dbo].[CF_Weekly_Casefill_Final_TY]
     LEFT JOIN
         [dbo].[CF_VEDW_PRD_MATL_DIM_N] ON [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#] = CAST([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] AS BIGINT)
     GROUP BY
         [GMI Division#], [GMI Division], [Type_Mapping], [Base Product#],
         [EQC_FCTR], [BUoM_Delivery Quantity], [BUoM_GMI Order Cut Total], [BUoM_GMI Delivery Cut Total])
WHERE
    (([GMI Division#] IN (01, 03, 12, 16, 50)
      AND [Distribution channel] IN ('RT', 'ML')) OR
     ([GMI Division#] IN (08) AND [Distribution channel] IN ('FS')))
    AND RIGHT([Fiscal Year/Period], 4) IN (2018)
GROUP BY
    [GMI Division#], [GMI Division], [Type_Mapping], [EQC_FCTR]

This throws an error "incorrect syntax near where"

Body:
Writing your code is the first part. You need to format it properly. Without that formatting, it is hard to read you.

This is a rewrite version of your query

WITH temp1 AS
(
  SELECT [GMI Division#],
  [GMI Division],[Type_Mapping],
  [Base Product#],
  SUM([BUoM_Delivery Quantity])*([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Delv_EQC_Fctr,
  (SUM([BUoM_GMI Order Cut Total]) + SUM([BUoM_GMI Delivery Cut Total])) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Cuts_EQC_Fctr
  FROM [dbo].[CF_Weekly_Casefill_Final_TY] LEFT JOIN [dbo].[CF_VEDW_PRD_MATL_DIM_N] ON
  [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#]=cast([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] as bigint)
  GROUP BY
  [GMI Division#],
  [GMI Division],
  [Type_Mapping],
  [Base Product#],
  [EQC_FCTR],
  [BUoM_Delivery Quantity],
  [BUoM_GMI Order Cut Total],
  [BUoM_GMI Delivery Cut Total]
)
SELECT [GMI Division#],[GMI Division],
        [Type_Mapping],Sum(Delv_EQC_Fctr) AS Delv_EQC_Fctr,
        Sum(Cuts_EQC_Fctr) AS Cuts_EQC_Fctr
FROM temp1
WHERE (([GMI Division#] in (01,03,12,16,50) and
([Distribution channel] IN ('RT','ML')) OR ([GMI Division#] in (08))
AND [Distribution channel] IN ('FS')))
AND  right([Fiscal Year/Period],4) IN (2018)
GROUP BY [GMI Division#],
        [GMI Division],
        [Type_Mapping],
        [EQC_FCTR]

I'm not sure where lies the problem with your WHERE clause.

To find the issue, I would operate that way.

Try to start with only one condition and see how it goes

If condition one is ok, add another one and etc

You have 4 conditions, it should be fast.

Best of luck

Update

There are website where you can format your code like this one -> http://www.sql-format.com/


问:
sort word in alphabet order in C
Below code is for a test sample given in https://www.testdome.com/for-developers/solve-question/9621

The question is:
Implement function sort_words that can sort an array of words which contain lowercase characters from english alphabet, in descending order.

For example, the array { "cherry", "orange", "apple" } should, after sorting, become { "orange", "cherry", "apple" }.

My code is:

```<code>#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void sort_words(char *words[], int count)
{
    char *x;

    for (int i = 0; i<count; i++)
    {
        for (int j = i + 1; j<count; j++)
        {
            if ((char)(*words[i]) < (char)(*words[j]))
            {
                x = words[j];
                words[j] = words[i];
                words[i] = x;
            }
        }

    }
}

#ifndef RunTests
int main()
{
    char *words[] = { "cherry", "orange", "apple" };

    sort_words(words, 3);

    for (int i = 0; i < 3; i++)
    {
        printf("%s ", words[i]);
    }
}
#endif
</code>```

Result is correct, but the system notices the fail information "Performance test on a dictionary: Time limit exceeded"

Why this error happens and how to solve this problem? Thanks!

答:
The above code looks working, but it is actually wrong.

If the input set is:

char *words[] = { "cherry", "orange", "apple", "oyster"};

Then the output is:

```<code>orange oyster cherry apple
</code>```

But the expected output is:

```<code>oyster orange cherry apple
</code>```

The reason for that is in your sorting algorithm this condition:

if ((char)(*words[i]) < (char)(*words[j]))

Is basically just comparing the first letters of the two character arrays.

NOTE: This is not C++ and the data is not stored in string data type in C++. Where the < operator is overloaded to compare two strings.

Hence, instead of that line, you can use the strcmp(), like this:

```<code>if (strcmp(words[i], words[j]) < 0)
</code>```

Here is your working code:

```<code>#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void sort_words(char *words[], int count)
{
    char *x;

    for (int i = 0; i<count; i++)
    {
        for (int j = i + 1; j<count; j++)
        {
            if (strcmp(words[i], words[j]) < 0)
            {
                x = words[j];
                words[j] = words[i];
                words[i] = x;
            }
        }

    }
}

#ifndef RunTests
int main()
{
    char *words[] = { "cherry", "orange", "apple", "oyester"};

    sort_words(words, 4);

    for (int i = 0; i < 4; i++)
    {
        printf("%s ", words[i]);
    }
    printf ("\n");
}
#endif
</code>```

Output:

```<code>oyester orange cherry apple
</code>```

Title: sort word in alphabet order in C

Body:
Below code is for a test sample given in https://www.testdome.com/for-developers/solve-question/9621

The question is:
Implement function sort_words that can sort an array of words which contain lowercase characters from english alphabet, in descending order.

For example, the array { "cherry", "orange", "apple" } should, after sorting, become { "orange", "cherry", "apple" }.

My code is:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void sort_words(char *words[], int count)
{
    char *x;

    for (int i = 0; i<count; i++)
    {
        for (int j = i + 1; j<count; j++)
        {
            if ((char)(*words[i]) < (char)(*words[j]))
            {
                x = words[j];
                words[j] = words[i];
                words[i] = x;
            }
        }

    }
}

#ifndef RunTests
int main()
{
    char *words[] = { "cherry", "orange", "apple" };

    sort_words(words, 3);

    for (int i = 0; i < 3; i++)
    {
        printf("%s ", words[i]);
    }
}
#endif

Result is correct, but the system notices the fail information "Performance test on a dictionary: Time limit exceeded"

Why this error happens and how to solve this problem? Thanks!

Body:
The above code looks working, but it is actually wrong.

If the input set is:

char *words[] = { "cherry", "orange", "apple", "oyster"};

Then the output is:

orange oyster cherry apple

But the expected output is:

oyster orange cherry apple

The reason for that is in your sorting algorithm this condition:

if ((char)(*words[i]) < (char)(*words[j]))

Is basically just comparing the first letters of the two character arrays.

NOTE: This is not C++ and the data is not stored in string data type in C++. Where the < operator is overloaded to compare two strings.

Hence, instead of that line, you can use the strcmp(), like this:

if (strcmp(words[i], words[j]) < 0)

Here is your working code:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void sort_words(char *words[], int count)
{
    char *x;

    for (int i = 0; i<count; i++)
    {
        for (int j = i + 1; j<count; j++)
        {
            if (strcmp(words[i], words[j]) < 0)
            {
                x = words[j];
                words[j] = words[i];
                words[i] = x;
            }
        }

    }
}

#ifndef RunTests
int main()
{
    char *words[] = { "cherry", "orange", "apple", "oyester"};

    sort_words(words, 4);

    for (int i = 0; i < 4; i++)
    {
        printf("%s ", words[i]);
    }
    printf ("\n");
}
#endif

Output:

oyester orange cherry apple


问:
create a foreach table in html email template php
I have an email template am trying to send to users after they have ordered for some items. to send the email am using inline css with html as the email teplate where it is saved as .html. the problem is how do i load all the items the user bought into a for each table and pass it to the email html template file before sending it

```<code><tbody style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;">
    {{ item }}
</tbody>
</code>```

this is my php for sending the mail

```<code>$mail = new PHPMailer;

$mail->From = "email@email.com";
$mail->FromName = "test";
$mail->addAddress($email); //Recipient name is optional
$mail->addReplyTo("email@email.com", "Reply");
$mail->isHTML(true);
$variables = array();
$variables['name'] = 'john';
$template = file_get_contents("eorder.html");
foreach($data as $row){
$eprodname = $this->get_name_from_id('product_name','product','product_id',$row['id']);
$variables['item'] ='<tr style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;page-break-inside: avoid;">
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">1</td>
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $eprodname .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['quantity'] .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['price'] .'</td>
</tr>';

}
foreach($variables as $key => $value)
{
  $template = str_replace('{{ '.$key.' }}', $value, $template);
}
$mail->Subject = "Order Details";
$mail->Body = $template;
$mail->Send();
</code>```

My problem: I have with this code is that if a user orders more than one product, this code will only load the last product on the table

答:
You are overriding your $variables['item'] key. You need to change this to array

```<code>foreach($data as $row){
$eprodname = $this->get_name_from_id('product_name','product','product_id',$row['id']);
$variables['item'][] ='<tr style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;page-break-inside: avoid;">
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">1</td>
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $eprodname .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['quantity'] .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['price'] .'</td>
</tr>';

}
</code>```

Body:
I have an email template am trying to send to users after they have ordered for some items. to send the email am using inline css with html as the email teplate where it is saved as .html. the problem is how do i load all the items the user bought into a for each table and pass it to the email html template file before sending it

    {{ item }}

this is my php for sending the mail

$mail = new PHPMailer;

$mail->From = "email@email.com";
$mail->FromName = "test";
$mail->addAddress($email); //Recipient name is optional
$mail->addReplyTo("email@email.com", "Reply");
$mail->isHTML(true);
$variables = array();
$variables['name'] = 'john';
$template = file_get_contents("eorder.html");
foreach($data as $row){
$eprodname = $this->get_name_from_id('product_name','product','product_id',$row['id']);
$variables['item'] ='

1
'. $eprodname .'
 '. $row['quantity'] .'
 '. $row['price'] .'

';

}
foreach($variables as $key => $value)
{
  $template = str_replace('{{ '.$key.' }}', $value, $template);
}
$mail->Subject = "Order Details";
$mail->Body = $template;
$mail->Send();

My problem: I have with this code is that if a user orders more than one product, this code will only load the last product on the table

Body:
You are overriding your $variables['item'] key. You need to change this to array

foreach($data as $row){
$eprodname = $this->get_name_from_id('product_name','product','product_id',$row['id']);
$variables['item'][] ='<tr style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;page-break-inside: avoid;">
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">1</td>
<td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $eprodname .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['quantity'] .'</td>
 <td style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;vertical-align: top;padding: 8px;line-height: 1.428571429;border-top: 1px solid #ddd;background-color: #fff!important;">'. $row['price'] .'</td>
</tr>';

}


问:
Restart Delphi Application Programmatically
It should not be possible to run multiple instances of my application. Therefore the project source contains:

```<code>CreateMutex (nil, False, PChar (ID));
if (GetLastError = ERROR_ALREADY_EXISTS) then
  Halt;
</code>```

Now I want to restart my application programmatically. The usual way would be:

```<code>AppName := PChar(Application.ExeName) ;
ShellExecute(Handle,'open', AppName, nil, nil, SW_SHOWNORMAL) ;
Application.Terminate;
</code>```

But this won't work in my case because of the mutex. Even if I release the mutex before starting the second instace it won't work because shutdown takes some time and two instance cannot run in parallel (because of common resources and other effects).

Is there a way to restart an application with such characteristics? (If possible without an additional executable)

Thanks in advance.

答:
Include in your ShellExecute some parameter, for example, /WaitForShutDown and create one more mutex. In your program, before the initialization, for example, in its .dpr file, insert something like:

if (Pos('/WaitForShutDown', CmdLine) <> 0) then
  WaitForSingleObject(ShutDownMutexHandle, INFINITE);

Also, in your program, after all the finalizations and releasing your common resources, include something like

ReleaseMutex(ShutDownMutexHandle);

Body:
It should not be possible to run multiple instances of my application. Therefore the project source contains:

CreateMutex (nil, False, PChar (ID));
if (GetLastError = ERROR_ALREADY_EXISTS) then
  Halt;

Now I want to restart my application programmatically. The usual way would be:

AppName := PChar(Application.ExeName) ;
ShellExecute(Handle,'open', AppName, nil, nil, SW_SHOWNORMAL) ;
Application.Terminate;

But this won't work in my case because of the mutex. Even if I release the mutex before starting the second instace it won't work because shutdown takes some time and two instance cannot run in parallel (because of common resources and other effects).

Is there a way to restart an application with such characteristics? (If possible without an additional executable)

Thanks in advance.


问:
Centered shear/skew in postscript
I'm trying to apply skewing to an image in postscript. I have successfully done it with:

```<code>[1 -0.5 -0.5 1 0 0] concat
</code>```

Where both -0.5 refers to a skew of 22.5 degrees on the vertical and horizontal axis. The problem is that the skewing is not centered, the center of the image is moved so my image doesn't stay on the same position after applying the skew.

How can I apply skewing while maintaining the position? I tried translating the image before/after skewing but I can't find how much I should translate the image so it always stays in the same position.

答:
Skewing works by altering the current transformation matrix, it isn't centered at all.

Image are described from their lower left corner unless you further alter the CTM, which is common practice when printing to PostScript from environments where images are drawn top down.

Basically, to solve your problem you need to understand the matrix manipulation and maths described in the PLRM.

Assuming you apply the concat at the point immediately before drawing the image, and no other CTM manipulations have taken place, then the bottom left corner of your image is at 0,0. The concat will not affect that (unless you have a Tx and Ty member in the matrix), but it will alter where the image is drawn. What you need to do is calculate the co-ordinate of the centre of your image when drawn normally, calculate where that co-ordinate is going to end up after the application of the modified CTM, then adjust the shear matrix by adding Tx and Ty values such that the centre co-ordinate will be in the required position. Or translate the origin appropriately.

The key point (probably) is that images have their own Matrix which is applied on top of the CTM; in order to calculate the user space co-ordinate of the centre of the image, you have to apply the image Matrix to the CTM, yourself. And you need to do it again with your shearing matrix applied as well to calculate the position of the centre of the transformed image. Once you have the co-ordinates of the centre of the vanilla image and the centre of the sheared image you know how to translate the current point so that the centre co-ordinate remains invariant.

You haven't supplied an example so I can't work through it for you and I don't have a simple working one to hand. I'll try and come up with one if I get time, and I'll post it here if I do.

Title: Centered shear/skew in postscript

Body:
I'm trying to apply skewing to an image in postscript. I have successfully done it with:

[1 -0.5 -0.5 1 0 0] concat

Where both -0.5 refers to a skew of 22.5 degrees on the vertical and horizontal axis. The problem is that the skewing is not centered, the center of the image is moved so my image doesn't stay on the same position after applying the skew.

How can I apply skewing while maintaining the position? I tried translating the image before/after skewing but I can't find how much I should translate the image so it always stays in the same position.


问:
MKMapItem.openInMaps() displays place mark exactly 50% of the time
I've found that running some code to display a location in maps view MKMapItem.openInMaps() only works exactly 50% of the time.

In fact it precisely alternates between the MKPlacemark being displayed and it not being displayed.

For example every 1st, 3rd, 5th, 7th ...nth time the code runs then it displays the place mark, but every 2nd, 4th, 6th, 8th ...mth time it runs, the place mark is not displayed.

This is 100% reproducible running the code posted below.

This seems like its a bug, but if so then I'm surprised its not been reported nor fixed previously. But given the fact the failures are precisely alternating between success and failure leads me to think there's something else going on, hence I'm posting here to see if anybody is familiar with this issue or there is something one is supposed to do which is missing from the code, or there is a workaround:

```<code>override func viewDidAppear(_ animated: Bool) {
    displayMap()
}

func displayMap()
{
    let geoCoder = CLGeocoder()
    geoCoder.geocodeAddressString("1 Infinite Loop, Cupertino,California") { (placemark: [CLPlacemark]?, error: Error?) -> Void in
        if error == nil
        {
            if let placemark = placemark, placemark.count > 0
            {
                let location            = placemark.first
                let latitude            = (location?.location?.coordinate.latitude)!
                let longitude           = (location?.location?.coordinate.longitude)!
                let coordinates         = CLLocationCoordinate2DMake(latitude, longitude)

                let regionDistance:CLLocationDistance = 100000
                let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)

                let options = [
                    MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
                    MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
                ]
                let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
                let mapItem = MKMapItem(placemark: placemark)

                mapItem.name = "Apple"
                mapItem.phoneNumber = "(405) 123-4567"
                mapItem.openInMaps(launchOptions: options)
            }
        }
        else
        {
            assert(false, "Unable to geocode")
        }
    }
}
</code>```

This is what the result looks like when the code is run for the first, third, fifth, seventh ... time

And this is the result when the code is run for the second, fourth, sixth, eighth... time

Notice in the failure screenshot that not only is the place mark not displayed on the map but the slide up is also empty.

(Currently observing this on 10.2 but have seen it on other versions too)

答:
On iOS 10.3.2 this issue still persists for me. However, this workaround is making mapItem not to disappear:

```<code>MKMapItem.openMaps(with: [mapItem], launchOptions: options)
</code>```

Body:
I've found that running some code to display a location in maps view MKMapItem.openInMaps() only works exactly 50% of the time.

In fact it precisely alternates between the MKPlacemark being displayed and it not being displayed.

For example every 1st, 3rd, 5th, 7th ...nth time the code runs then it displays the place mark, but every 2nd, 4th, 6th, 8th ...mth time it runs, the place mark is not displayed.

This is 100% reproducible running the code posted below.

This seems like its a bug, but if so then I'm surprised its not been reported nor fixed previously. But given the fact the failures are precisely alternating between success and failure leads me to think there's something else going on, hence I'm posting here to see if anybody is familiar with this issue or there is something one is supposed to do which is missing from the code, or there is a workaround:

override func viewDidAppear(_ animated: Bool) {
    displayMap()
}

func displayMap()
{
    let geoCoder = CLGeocoder()
    geoCoder.geocodeAddressString("1 Infinite Loop, Cupertino,California") { (placemark: [CLPlacemark]?, error: Error?) -> Void in
        if error == nil
        {
            if let placemark = placemark, placemark.count > 0
            {
                let location            = placemark.first
                let latitude            = (location?.location?.coordinate.latitude)!
                let longitude           = (location?.location?.coordinate.longitude)!
                let coordinates         = CLLocationCoordinate2DMake(latitude, longitude)

                let regionDistance:CLLocationDistance = 100000
                let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)

                let options = [
                    MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
                    MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
                ]
                let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
                let mapItem = MKMapItem(placemark: placemark)

                mapItem.name = "Apple"
                mapItem.phoneNumber = "(405) 123-4567"
                mapItem.openInMaps(launchOptions: options)
            }
        }
        else
        {
            assert(false, "Unable to geocode")
        }
    }
}

This is what the result looks like when the code is run for the first, third, fifth, seventh ... time

And this is the result when the code is run for the second, fourth, sixth, eighth... time

Notice in the failure screenshot that not only is the place mark not displayed on the map but the slide up is also empty.

(Currently observing this on 10.2 but have seen it on other versions too)

Body:
On iOS 10.3.2 this issue still persists for me. However, this workaround is making mapItem not to disappear:

MKMapItem.openMaps(with: [mapItem], launchOptions: options)


问:
Slick slider: adding space in between images shown
Maybe I am just being ridiculous and this is a simple thing but I am trying to add spacing in between the images shown using slick slider.

The JS

```<code>$('.slider').slick({
    infinite: true,
    speed: 700,
    arrows: true,
    slidesToShow: 2,
    slidesToScroll: 2,
    dots: false,
    responsive: [ { settings: "unslick" ## Heading ##}, ]
});
</code>```

And my attempt at adding the space with css:

```<code>.slick-slide {
    &:nth-of-type(odd){
        padding-left:0px;
        padding-right:100px;
    }
    &:nth-of-type(even){
        padding-right:0px;
        padding-left:100px;
    }
}
</code>```

If there is anyone who can help that would be greatly appreciated! Thanks in advance!

答:
Instead of applying properties to the .slick-slide selector directly, you should prefer apply them to a child element.

For example, if the HTML code is,

```<code><div class="slider">
    <div><h3>1</h3></div>
    <div><h3>2</h3></div>
    <div><h3>3</h3></div>
</div>
</code>```

then the SASS should be,

```<code>.slick-slide {
  h3{
    background: red;
    color: white;
    font-size: 36px;
    line-height: 100px;
    margin: 10px;
    padding: 2%;
    position: relative;
    text-align: center;
  }
}
</code>```

Note that the margin here is causing the required spacing.
Check out the codepen I have created for you to have better understanding.

Body:
Maybe I am just being ridiculous and this is a simple thing but I am trying to add spacing in between the images shown using slick slider.

The JS

$('.slider').slick({
    infinite: true,
    speed: 700,
    arrows: true,
    slidesToShow: 2,
    slidesToScroll: 2,
    dots: false,
    responsive: [ { settings: "unslick" ## Heading ##}, ]
});

And my attempt at adding the space with css:

.slick-slide {
    &:nth-of-type(odd){
        padding-left:0px;
        padding-right:100px;
    }
    &:nth-of-type(even){
        padding-right:0px;
        padding-left:100px;
    }
}

If there is anyone who can help that would be greatly appreciated! Thanks in advance!

Body:
Instead of applying properties to the .slick-slide selector directly, you should prefer apply them to a child element.

For example, if the HTML code is,

<div class="slider">
    <div><h3>1</h3></div>
    <div><h3>2</h3></div>
    <div><h3>3</h3></div>
</div>

then the SASS should be,

.slick-slide {
  h3{
    background: red;
    color: white;
    font-size: 36px;
    line-height: 100px;
    margin: 10px;
    padding: 2%;
    position: relative;
    text-align: center;
  }
}

Note that the margin here is causing the required spacing.
Check out the codepen I have created for you to have better understanding.


答:
Validator::extend('before_equal', function($attribute, $value, $parameters, $validator) { return strtotime($validator->getData()[$parameters[0]]) >= strtotime($value); });
  Or alternative is upgrade to 5.3</p>

Title: after_or_equal validation does not work in laravel 5.2

Body:
I want to compare start_date with end_date ,
and end_date should be equal or greater then start_date,
i am using after_or_equal validation.

return Validator::make($data, [
      'start_date' => 'required',
      'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date'
]);

after_or_create validation of laravel5.2 return error like this.
Method [validateAfterOrEqual] does not exist.