问:
Navigation Drawer closing on click event

I am unable to click any of my menu items, I cannot swipe from right to left to close the drawer, although, whenever it is opened and I click on the screen it immediately closes.

I have pretty much tried every answer posted to similar questions here on stack overflow and Github:

```<code> public class BottomActivity extends AppCompatActivity
    implements GestureOverlayView.OnGesturePerformedListener {

RadioGroup radioGroup;
RadioButton Rd1, Rd2, Rd3, Rd4;
DrawerLayout drawer;

@SuppressLint({"RtlHardcoded", "ClickableViewAccessibility"})
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_bottom );
    new GestureOverlayView( this );

    Objects.requireNonNull( getSupportActionBar() ).setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM );
    getSupportActionBar().setCustomView( R.layout.abs_layout_home );

    radioGroup = findViewById( R.id.radioGroup );
    Rd1 = findViewById( R.id.radioButton );
    Rd2 = findViewById( R.id.radioButton2 );
    Rd3 = findViewById( R.id.radioButton3 );
    Rd4 = findViewById( R.id.radioButton4 );
    radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (Rd1.isChecked()) {
                Intent intent = new Intent( getApplicationContext(), BottomActivity.class );
                startActivity( intent );
            }
            if (Rd2.isChecked()) {
                Intent intent1 = new Intent( getApplicationContext(), DashBoard.class );
                startActivity( intent1 );
            }
            if (Rd3.isChecked()) {
                Intent intent2 = new Intent( getApplicationContext(), SettingsActivity.class );
                startActivity( intent2 );
            } else {
                if (Rd4.isChecked()) {
                    Intent intent3 = new Intent( getApplicationContext(), Messages.class );
                    startActivity( intent3 );
                }
            }
        }
    } );

}

@Override
public void onBackPressed() {
    if (drawer.isDrawerOpen( GravityCompat.START )) {
        drawer.closeDrawer( GravityCompat.START );
    } else {
        super.onBackPressed();
    }
}

public void onDrawerSlide() {
    DrawerLayout drawerLayout = findViewById( R.id.DrawerLayout);
    drawerLayout.addDrawerListener(
            new DrawerLayout.DrawerListener() {
                @Override
                public void onDrawerSlide(@NonNull View view, float v) {

                }

                @Override
                public void onDrawerOpened(@NonNull View view) {

                }

                @Override
                public void onDrawerClosed(@NonNull View view) {

                }

                @Override
                public void onDrawerStateChanged(int i) {

                }
            }
    );
}

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.nav_profile:
            startActivity( new Intent(BottomActivity.this, ProfileActivity.class));
            return true;
        case R.id.nav_settings:
            startActivity( new Intent( BottomActivity.this, SettingsActivity.class));
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

}
</code>```

Here is my navigation drawer XML code:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
tools:openNavigationView="start"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
    app:expandedTitleGravity="top"
    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
        android:background="@color/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:minHeight="?attr/actionBarSize"
    app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>

<include
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_nav_drawer"
    app:menu="@menu/activity_nav_drawer_drawer" />
</code>```

Here is my activities XML code:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:elevation="10dp"
android:foregroundGravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".BottomActivity"
tools:targetApi="lollipop"
app:layout_collapseMode="parallax">

    <include
    android:id="@+id/include"
    layout="@layout/activity_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

    <RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/colorPrimary"
    android:gravity="bottom"
    android:orientation="horizontal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

     <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/iconColor"
        android:checked="true"
        android:drawableTop="@drawable/ic_home_black_24dp"
        android:padding="10dp"
        android:tag="1"
        android:text="@string/home"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

     <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconColor"
        android:drawableTop="@drawable/ic_notifications_black_24dp"
        android:padding="10dp"
        android:text="@string/notifications"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

    <RadioButton
        android:id="@+id/radioButton3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconColor"
        android:drawableTop="@drawable/ic_people_icon"
        android:padding="10dp"
        android:text="@string/People"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

    <RadioButton
        android:id="@+id/radioButton4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconcolor"
        android:drawableTop="@drawable/ic_msg_icon"
        android:padding="10dp"
        android:text="@string/Messages"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

</RadioGroup>

</android.support.design.widget.CoordinatorLayout>
</code>```

答:
In BottomActivity add this in your onCreate:

```<code>    NavigationView nav_view;

    nav_view = findViewById(R.id.nav_view);   //select nav_view from activity_drawer_layout

    nav_view.setNavigationItemSelectedListener(this);
</code>```

In activity_drawer_layout.xml put the NavigationView above the closing tag for the DrawerLayout.

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="@+id/DrawerLayout">

<include
    android:id="@+id/include"
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="0dp"
    android:layout_height="0dp" />
<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="0dp"
    android:layout_height="673dp"
    android:padding="16dp"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/name" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/age"/>
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:layout_constraintBottom_toBottomOf="@+id/nav_header" />

<include
    android:id="@+id/include"
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:layout_gravity="start"
    android:clickable="true"
    android:focusable="true"
    android:orientation="vertical"
    app:headerLayout="@layout/nav_header_nav_drawer"
    app:menu="@menu/activity_nav_drawer_drawer" />

</android.support.v4.widget.DrawerLayout>
</code>```

Body:
I am unable to click any of my menu items, I cannot swipe from right to left to close the drawer, although, whenever it is opened and I click on the screen it immediately closes.

I have pretty much tried every answer posted to similar questions here on stack overflow and Github:

 public class BottomActivity extends AppCompatActivity
    implements GestureOverlayView.OnGesturePerformedListener {

RadioGroup radioGroup;
RadioButton Rd1, Rd2, Rd3, Rd4;
DrawerLayout drawer;

@SuppressLint({"RtlHardcoded", "ClickableViewAccessibility"})
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_bottom );
    new GestureOverlayView( this );

    Objects.requireNonNull( getSupportActionBar() ).setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM );
    getSupportActionBar().setCustomView( R.layout.abs_layout_home );

    radioGroup = findViewById( R.id.radioGroup );
    Rd1 = findViewById( R.id.radioButton );
    Rd2 = findViewById( R.id.radioButton2 );
    Rd3 = findViewById( R.id.radioButton3 );
    Rd4 = findViewById( R.id.radioButton4 );
    radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (Rd1.isChecked()) {
                Intent intent = new Intent( getApplicationContext(), BottomActivity.class );
                startActivity( intent );
            }
            if (Rd2.isChecked()) {
                Intent intent1 = new Intent( getApplicationContext(), DashBoard.class );
                startActivity( intent1 );
            }
            if (Rd3.isChecked()) {
                Intent intent2 = new Intent( getApplicationContext(), SettingsActivity.class );
                startActivity( intent2 );
            } else {
                if (Rd4.isChecked()) {
                    Intent intent3 = new Intent( getApplicationContext(), Messages.class );
                    startActivity( intent3 );
                }
            }
        }
    } );

}

@Override
public void onBackPressed() {
    if (drawer.isDrawerOpen( GravityCompat.START )) {
        drawer.closeDrawer( GravityCompat.START );
    } else {
        super.onBackPressed();
    }
}

public void onDrawerSlide() {
    DrawerLayout drawerLayout = findViewById( R.id.DrawerLayout);
    drawerLayout.addDrawerListener(
            new DrawerLayout.DrawerListener() {
                @Override
                public void onDrawerSlide(@NonNull View view, float v) {

                }

                @Override
                public void onDrawerOpened(@NonNull View view) {

                }

                @Override
                public void onDrawerClosed(@NonNull View view) {

                }

                @Override
                public void onDrawerStateChanged(int i) {

                }
            }
    );
}

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.nav_profile:
            startActivity( new Intent(BottomActivity.this, ProfileActivity.class));
            return true;
        case R.id.nav_settings:
            startActivity( new Intent( BottomActivity.this, SettingsActivity.class));
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

}

Here is my navigation drawer XML code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
tools:openNavigationView="start"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
    app:expandedTitleGravity="top"
    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
        android:background="@color/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:minHeight="?attr/actionBarSize"
    app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>

<include
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_nav_drawer"
    app:menu="@menu/activity_nav_drawer_drawer" />

Here is my activities XML code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:elevation="10dp"
android:foregroundGravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".BottomActivity"
tools:targetApi="lollipop"
app:layout_collapseMode="parallax">

    <include
    android:id="@+id/include"
    layout="@layout/activity_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

    <RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/colorPrimary"
    android:gravity="bottom"
    android:orientation="horizontal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

     <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/iconColor"
        android:checked="true"
        android:drawableTop="@drawable/ic_home_black_24dp"
        android:padding="10dp"
        android:tag="1"
        android:text="@string/home"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

     <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconColor"
        android:drawableTop="@drawable/ic_notifications_black_24dp"
        android:padding="10dp"
        android:text="@string/notifications"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

    <RadioButton
        android:id="@+id/radioButton3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconColor"
        android:drawableTop="@drawable/ic_people_icon"
        android:padding="10dp"
        android:text="@string/People"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

    <RadioButton
        android:id="@+id/radioButton4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:button="@null"
        android:buttonTint="@color/uiconcolor"
        android:drawableTop="@drawable/ic_msg_icon"
        android:padding="10dp"
        android:text="@string/Messages"
        android:textAlignment="center"
        android:textColor="@color/color"
        android:textSize="12sp"/>

</RadioGroup>

</android.support.design.widget.CoordinatorLayout>

Body:
In BottomActivity add this in your onCreate:

    NavigationView nav_view;

    nav_view = findViewById(R.id.nav_view);   //select nav_view from activity_drawer_layout

    nav_view.setNavigationItemSelectedListener(this);

In activity_drawer_layout.xml put the NavigationView above the closing tag for the DrawerLayout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="@+id/DrawerLayout">

<include
    android:id="@+id/include"
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="0dp"
    android:layout_height="0dp" />
<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="0dp"
    android:layout_height="673dp"
    android:padding="16dp"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/name" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/age"/>
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:layout_constraintBottom_toBottomOf="@+id/nav_header" />

<include
    android:id="@+id/include"
    layout="@layout/app_bar_nav_drawer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:layout_gravity="start"
    android:clickable="true"
    android:focusable="true"
    android:orientation="vertical"
    app:headerLayout="@layout/nav_header_nav_drawer"
    app:menu="@menu/activity_nav_drawer_drawer" />

</android.support.v4.widget.DrawerLayout>


来源: stackexchange

问:
Creating a serial actually creates a bigserial
When I create a test table with a serial type,
The serial is actually a bigserial type.
Does this cause any issues?
Is this a bug?
PostgreSQL 9.5.3
Red Hat 64-bit</p>

```<code>#> CREATE TABLE test (id SERIAL PRIMARY KEY, name text);
#> \d+ test
    Table "public.test"
 Column |  Type   |                     Modifiers                     | Storage  | Stats target | Description
--------+---------+---------------------------------------------------+----------+--------------+-------------
 id     | integer | not null default nextval('test_id_seq'::regclass) | plain    |              |
 name   | text    |                                                   | extended |              |
Indexes:
"test_pkey" PRIMARY KEY, btree (id)

#> \d+ test_id_seq
    Sequence "public.test_id_seq"
    Column     |  Type   |        Value        | Storage
---------------+---------+---------------------+---------
 sequence_name | name    | test_id_seq         | plain
 last_value    | bigint  | 1                   | plain
 start_value   | bigint  | 1                   | plain
 increment_by  | bigint  | 1                   | plain
 max_value     | bigint  | 9223372036854775807 | plain
 min_value     | bigint  | 1                   | plain
 cache_value   | bigint  | 1                   | plain
 log_cnt       | bigint  | 0                   | plain
 is_cycled     | boolean | f                   | plain
 is_called     | boolean | f                   | plain
</code>```

答:
SERIAL isn't really a type; as explained in the 9.5 docs, it's just shorthand for a collection of commands:

The data types smallserial, serial and bigserial are not true types, but merely a notational convenience [...] In the current implementation, specifying:

```<code>CREATE TABLE tablename (
    colname SERIAL
);
</code>```

is equivalent to specifying:

```<code>CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
</code>```

As you can see, the integer type applies only to the table column, and is not mentioned in the definition of the sequence. The CREATE SEQUENCE statement in 9.5 doesn't allow you to specify a type; all sequences are based on bigint counters, hence the bigint columns in your \d+ output.

This is no longer the case, as of Postgres 10: you can now attach a data type to a sequence, and as per the new docs, the sequence in the SERIAL example above is now defined as:

```<code>CREATE SEQUENCE tablename_colname_seq AS integer;
</code>```

This really only serves to limit the max value of the sequence - the internal counter is still a bigint - but it is reported as the appropriate type by \d+ (which now looks quite different):

```<code>test=# \d+ tablename_colname_seq
               Sequence "public.tablename_colname_seq"
  Type   | Start | Minimum |  Maximum   | Increment | Cycles? | Cache
---------+-------+---------+------------+-----------+---------+-------
 integer |     1 |       1 | 2147483647 |         1 | no      |     1
</code>```

ContentLicense: CC BY-SA 4.0

Body:
When I create a test table with a serial type,
The serial is actually a bigserial type.
Does this cause any issues?
Is this a bug?
PostgreSQL 9.5.3
Red Hat 64-bit

#> CREATE TABLE test (id SERIAL PRIMARY KEY, name text);
#> \d+ test
    Table "public.test"
 Column |  Type   |                     Modifiers                     | Storage  | Stats target | Description
--------+---------+---------------------------------------------------+----------+--------------+-------------
 id     | integer | not null default nextval('test_id_seq'::regclass) | plain    |              |
 name   | text    |                                                   | extended |              |
Indexes:
"test_pkey" PRIMARY KEY, btree (id)

#> \d+ test_id_seq
    Sequence "public.test_id_seq"
    Column     |  Type   |        Value        | Storage
---------------+---------+---------------------+---------
 sequence_name | name    | test_id_seq         | plain
 last_value    | bigint  | 1                   | plain
 start_value   | bigint  | 1                   | plain
 increment_by  | bigint  | 1                   | plain
 max_value     | bigint  | 9223372036854775807 | plain
 min_value     | bigint  | 1                   | plain
 cache_value   | bigint  | 1                   | plain
 log_cnt       | bigint  | 0                   | plain
 is_cycled     | boolean | f                   | plain
 is_called     | boolean | f                   | plain

Body:
SERIAL isn't really a type; as explained in the 9.5 docs, it's just shorthand for a collection of commands:

The data types smallserial, serial and bigserial are not true types, but merely a notational convenience [...] In the current implementation, specifying:

CREATE TABLE tablename (
    colname SERIAL
);

is equivalent to specifying:

CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;

As you can see, the integer type applies only to the table column, and is not mentioned in the definition of the sequence. The CREATE SEQUENCE statement in 9.5 doesn't allow you to specify a type; all sequences are based on bigint counters, hence the bigint columns in your \d+ output.

This is no longer the case, as of Postgres 10: you can now attach a data type to a sequence, and as per the new docs, the sequence in the SERIAL example above is now defined as:

CREATE SEQUENCE tablename_colname_seq AS integer;

This really only serves to limit the max value of the sequence - the internal counter is still a bigint - but it is reported as the appropriate type by \d+ (which now looks quite different):

test=# \d+ tablename_colname_seq
               Sequence "public.tablename_colname_seq"
  Type   | Start | Minimum |  Maximum   | Increment | Cycles? | Cache
---------+-------+---------+------------+-----------+---------+-------
 integer |     1 |       1 | 2147483647 |         1 | no      |     1


问:
I am currently working with Forge RCDB and MongoDB, but there is no data in Database and cost Breaddown, always show loading
I am currently working with Forge RCDB and MongoDB,  but there is no data in Database and cost Breaddown, always show loading</p>

答:
Make sure you have followed the README to import the sample data to your MongoDB properly and use models that are compatible with RCDB:

1/ You need to translate at least one model using your own Forge credentials, so it can be loaded by your app. In order to do that take a look at the step-by-step tutorial from the Model Derivative API to understand exactly what this is about.
  If you want to skip that manual process you can use one of our live sample: https://models.autodesk.io. This app lets you put your credentials and translate a model on your behalf. Another option would be to deploy to heroku the Forge boiler plate sample #5. Make sure you deploy Project #5. This set up is more straightforward since it doesn't require any Cloud database or pre-translated models. It will let you upload, translate and manage further models as well.

Once you have translated at least one model, take note of its URN, that's the base64 encoded objectId. You also need a model which has some "Material" properties to be compatible with forge-rcdb because it is expecting components with that property. You can use Engine.dwf placed in the resource/models directory of this project.

Just gave it a go myself and it worked well:


问:
positioning labels on geom_bar
I am trying to create a horizontal bar chart with category labels using ggplot.

I have been able to create the plot without hassles, and can put labels on, however I suffer issues with the formatting. Ultimately I would like to have my label within the bar if it fits, otherwise just outside the bar without truncating the label.

The following are what I have tried so far.

Data

```<code>dt1 <- data.table(x=c("a","b","c","d","e"), y=c(43,52,296,102,157), y2=c(50,10,100,45,80))
</code>```

Chart 1

```<code>ggplot() + geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") + coord_flip() +
  geom_text(data=dt1, aes(x=x, y=y, label=paste0("$",y," from ",y2," records")),hjust=0)
</code>```

As you can see below the labels get truncated.

Chart 2

I then came across this question which was helpful and made me realise that I was setting the label position based on my y variable so I have hardcoded it now and use hjust to pad it from the axis.

```<code>ggplot() + geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") + coord_flip() +
  geom_text(data=dt1, aes(x=x, y=0, label=paste0("$",y," from ",y2," records")),hjust=-0.1)
</code>```

But you can see below that only 2 of the labels fit within the bar, so I would prefer the others to be placed at the end, on the outside of the bar like in chart 1.

Is there a programatic way I can get the best of both worlds from chart 1 and chart 2?

答:
Move the hjust into the aes so we may vary off the value, then move it if the bar is a certain way past the max. It’s a bit hacky still, since it makes assumptions about the scaling, but looks pretty good. Divisor may need tweaking:

```<code>library(tidyverse)

dt1 <- data.frame(x=c("a","b","c","d","e"), y=c(43,52,296,102,157), y2=c(50,10,100,45,80))

ggplot() +
  geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") +
  coord_flip() +
  geom_text(
    data=dt1,
    aes(
      x=x, y=y,
      label=paste0("$",y," from ",y2," records"),
      hjust=ifelse(y < max(dt1$y) / 1.5, -0.1, 1.1), # <- Here lies the magic
    ),
  )
</code>```

Results in this plot:

ContentLicense: CC BY-SA 3.0

Title: positioning labels on geom_bar

Body:
I am trying to create a horizontal bar chart with category labels using ggplot.

I have been able to create the plot without hassles, and can put labels on, however I suffer issues with the formatting. Ultimately I would like to have my label within the bar if it fits, otherwise just outside the bar without truncating the label.

The following are what I have tried so far.

Data

dt1 <- data.table(x=c("a","b","c","d","e"), y=c(43,52,296,102,157), y2=c(50,10,100,45,80))

Chart 1

ggplot() + geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") + coord_flip() +
  geom_text(data=dt1, aes(x=x, y=y, label=paste0("$",y," from ",y2," records")),hjust=0)

As you can see below the labels get truncated.

Chart 2

I then came across this question which was helpful and made me realise that I was setting the label position based on my y variable so I have hardcoded it now and use hjust to pad it from the axis.

ggplot() + geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") + coord_flip() +
  geom_text(data=dt1, aes(x=x, y=0, label=paste0("$",y," from ",y2," records")),hjust=-0.1)

But you can see below that only 2 of the labels fit within the bar, so I would prefer the others to be placed at the end, on the outside of the bar like in chart 1.

Is there a programatic way I can get the best of both worlds from chart 1 and chart 2?

Body:
Move the hjust into the aes so we may vary off the value, then move it if the bar is a certain way past the max. It’s a bit hacky still, since it makes assumptions about the scaling, but looks pretty good. Divisor may need tweaking:

library(tidyverse)

dt1 <- data.frame(x=c("a","b","c","d","e"), y=c(43,52,296,102,157), y2=c(50,10,100,45,80))

ggplot() +
  geom_bar(data=dt1, aes(x=x, y=y), stat="identity",fill="red") +
  coord_flip() +
  geom_text(
    data=dt1,
    aes(
      x=x, y=y,
      label=paste0("$",y," from ",y2," records"),
      hjust=ifelse(y < max(dt1$y) / 1.5, -0.1, 1.1), # <- Here lies the magic
    ),
  )

Results in this plot:


问:
ReactJS: how can I know what parameters are passed automatically from a component when onChange is triggered?
This is probably a very newbie question, but I can't figure out how to know what parameters are passed to a function. Let me show you what I mean:

I have the following code in my constructor:

```<code>this.handleFormInput = this.handleFormInput.bind(this);
</code>```

And then:

```<code>  handleFormInput(event) {
    console.log('event' + event.target.name);
    this.setState({
      [event.target.name]: event.target.value
    })
  }
</code>```

And finally the form:

```<code>    <Form>
      <Form.Group>
        <Form.Field style={{width: '90%'}}>
          <input placeholder='Section title'
            id={section.id}
            name='title'
            value={section.title}
            onChange={this.handleInput}
          />
        </Form.Field>
      </Form.Group>
    </Form>
</code>```

So far so good: the event parameter is passed automatically and I can reach it by adding it as a parameter in my function.

Now I have a Dropdown component. In the constructor I have:

```<code>this.handleDropDownInput = this.handleDropDownInput.bind(this);
</code>```

The function:

```<code>  handleDropDownInput(event, data) {
    console.log('value ' + data.value);
    this.setState({
      [data.name]: data.value
    })
  }
</code>```

Then the semantic-ui Dropdown:

```<code>      <Dropdown
        fluid
        placeholder='Language'
        search
        selection
        options={languages}
        defaultValue='gb'
        name='language'
        onChange={this.handleDropDownInput}
      />
</code>```

Why I have to use the 'data' parameter to get the value on the Dropdown component? Why I can't use just the event? How can I know what parameters are passed automatically when onChange is triggered?

Is it appropriate to have a different function for different input components (dropdown, form fields etc)? Can and should I make one function to manage all user input?

For example, I came up with this function to handle both dropdown and form fields onChange events:

```<code>  handleInput(event, data) {
    if (data !== undefined) {
      console.log('value ' + data.value);
      this.setState({
        [data.name]: data.value
      })
    } else {
      console.log('event ' + event.target.name);
      this.setState({
        [event.target.name]: event.target.value

      })
    }
</code>```

Is it good or bad practice? Thanks.

答:
In javascript there are a few ways you can get all the arguments, depending on your environment.

In pre-es6 javascript (pre "strict mode," which is what es6 modules default to) there was a dynamic variable called "arguments." You can see a reference to it here: mdn

In newer es6 style environments, you can use what is called "rest parameter syntax" to get something similar, which will be an array of the arguments. mdn

In general, that information should be in the docs for the library or react component you are using.

function someFn(...args) {
  console.log(args)
}

someFn("hey", "there");```

Body:
This is probably a very newbie question, but I can't figure out how to know what parameters are passed to a function. Let me show you what I mean:

I have the following code in my constructor:

this.handleFormInput = this.handleFormInput.bind(this);

And then:

  handleFormInput(event) {
    console.log('event' + event.target.name);
    this.setState({
      [event.target.name]: event.target.value
    })
  }

And finally the form:

    <Form>
      <Form.Group>
        <Form.Field style={{width: '90%'}}>
          <input placeholder='Section title'
            id={section.id}
            name='title'
            value={section.title}
            onChange={this.handleInput}
          />
        </Form.Field>
      </Form.Group>
    </Form>

So far so good: the event parameter is passed automatically and I can reach it by adding it as a parameter in my function.

Now I have a Dropdown component. In the constructor I have:

this.handleDropDownInput = this.handleDropDownInput.bind(this);

The function:

  handleDropDownInput(event, data) {
    console.log('value ' + data.value);
    this.setState({
      [data.name]: data.value
    })
  }

Then the semantic-ui Dropdown:

      <Dropdown
        fluid
        placeholder='Language'
        search
        selection
        options={languages}
        defaultValue='gb'
        name='language'
        onChange={this.handleDropDownInput}
      />

Why I have to use the 'data' parameter to get the value on the Dropdown component? Why I can't use just the event? How can I know what parameters are passed automatically when onChange is triggered?

Is it appropriate to have a different function for different input components (dropdown, form fields etc)? Can and should I make one function to manage all user input?

For example, I came up with this function to handle both dropdown and form fields onChange events:

  handleInput(event, data) {
    if (data !== undefined) {
      console.log('value ' + data.value);
      this.setState({
        [data.name]: data.value
      })
    } else {
      console.log('event ' + event.target.name);
      this.setState({
        [event.target.name]: event.target.value

      })
    }

Is it good or bad practice? Thanks.


问:
Beginner JavaScript into HTML
I am very new to coding, I started taking a programming class a month ago and we were recently assigned our first project. I am trying to get my javascript code into my index.html. So far I have this in my html page:

```<code><script src="/project1/prices.js" type='Javascript/text></script>`
</code>```

My javascript page currently has this in it:

```<code>var price1Name = "Tickets for 18 and under";
var price2Name = "Tickets for 18 and over";
var price3Name = "T-shirt (all sizes)";
var price4Name = "Jackets (all sizes)";

var price1price = "$5.00";
var price2price = "$10.00";
var price3price = "$15.00";
var price4price = "$20.00";

document.write(price1Name);
document.write(price1price);
document.write(price2Name);
document.write(price2price);
document.write(price3Name);
document.write(price3price);
document.write(price4Name);
document.write(price4price);
</code>```

All I am trying to do is input this code into my Html page so that I am able to display the items and their prices. I can't seem to figure out what I am doing wrong. Thanks for your time, anything helps!

答:
```<code><!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script>
//code
</script>
</body>
</html>
</code>```

You can paste your JavaScript code between the script tags in the
  body. This will allow you to insert JavaScript code into your HTML
  page.

Title: Beginner JavaScript into HTML

Body:
I am very new to coding, I started taking a programming class a month ago and we were recently assigned our first project. I am trying to get my javascript code into my index.html. So far I have this in my html page:

`

My javascript page currently has this in it:

var price1Name = "Tickets for 18 and under";
var price2Name = "Tickets for 18 and over";
var price3Name = "T-shirt (all sizes)";
var price4Name = "Jackets (all sizes)";

var price1price = "$5.00";
var price2price = "$10.00";
var price3price = "$15.00";
var price4price = "$20.00";

document.write(price1Name);
document.write(price1price);
document.write(price2Name);
document.write(price2price);
document.write(price3Name);
document.write(price3price);
document.write(price4Name);
document.write(price4price);

All I am trying to do is input this code into my Html page so that I am able to display the items and their prices. I can't seem to figure out what I am doing wrong. Thanks for your time, anything helps!

Body:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script>
//code
</script>
</body>
</html>

You can paste your JavaScript code between the script tags in the
  body. This will allow you to insert JavaScript code into your HTML
  page.


问:
How do you organise/layout your test scripts
I'm interested in how others organise their test scripts or have seen good test scripts organised anywhere they've worked. Also, what level of detail is in those test scripts. This specifically relates to test scripts created for manual testing as opposed to those created for any automated test purposes.

The problem as I see it is this, there is a lot of complexity in test scripts but without the benefit of the principles used in organising a complex or large code base. You need to be able to specify what a piece of code should do but without boring someone to death as they read it.

Also, How do you layout test scripts, I'm not keen to create fully specified scripts suitable to be run by data entry types as that isn't the team we have and the overhead of maintaining them seems too high. Also, it feels to me that specifying the process in such detail removes responsibility from the person actually doing the testing for the quality of the product. Do people specify every button click and value to be entered? If not then what level of detail is specified.

答: Tests can be grouped by priority. The BVT/smoke tests could have the highest priority with functional, integration, regression, localization, stress, and performance having lower priorities. Depending on your test pass you would select a priority and run all tests with that or higher priorities. All you need to do is determine which priority a particular test is. </p>

OwnerDisplayName: Craig Delthony

ContentLicense: CC BY-SA 2.5


问:
Change the editor Xcode 4 uses for property lists?
I like PlistEdit Pro way better than the default plist editor that comes with Xcode 4.  Is there any way to tell Xcode 4 to always use PlistEdit Pro an an alternate editor for my property lists?</p>

答:
First set PlistEdit Pro as the default application to open property list files. You can do this from the Finder by selecting a .plist file and bringing up the Info panel.

After that, the "Open with external editor" option will be available when you right-click on a .plist file in Xcode 4's project navigator.


问:
Creating vector of vectors (2D array) inside a class - Error:C++ requires a type specifier for all declarations
So I have procedurally programmed a way to integrate equations using the Runge-Kutta 4(RK4) method in C++. I am currently trying to create an RK4 class to add more functionality to my program. However, when I set up my 2D arrays in the class, I receive the "C++ requires a type specifier for all declarations" error, that I didn't receive in the original program.

At first, I was using namespace std;, however I came across an answer that said that that was bad programming practice, so I erased that line and called std::vector instead. I also made sure to include the vector library, to no avail.

```<code>#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>

class RK4 {
public:
    RK4(double x_i, double y_i, double z_i, double vx_i, double vy_i, double vz_i);
    //time-related stuff
    double dt = 0.01;
    int numtimes = 1000;

    int numvar = 3;
    double mu = 398589590898200.0;

    //setting up variables
    std::vector<vector<double> > position(numtimes,vector<double>(numvar));
    std::vector<vector<double> > velocity(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk1(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk2(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk3(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk4(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk1(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk2(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk3(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk4(numtimes,vector<double>(numvar));
</code>```

This is how I constructed the code in my original program, with no problem:

```<code>#include <iostream>
#include <ostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
// time related things
    //double t_i = 0; // initial time
    double dt = 0.01; // time step
    int numtimes = 10000; // how many steps taken

    vector<vector<double> > position(numtimes,vector<double>(numvar));
    vector<vector<double> > velocity(numtimes,vector<double>(numvar));

    vector<vector<double> > rk1(numtimes,vector<double>(numvar));
    vector<vector<double> > rk2(numtimes,vector<double>(numvar));
    vector<vector<double> > rk3(numtimes,vector<double>(numvar));
    vector<vector<double> > rk4(numtimes,vector<double>(numvar));
    vector<vector<double> > vk1(numtimes,vector<double>(numvar));
    vector<vector<double> > vk2(numtimes,vector<double>(numvar));
    vector<vector<double> > vk3(numtimes,vector<double>(numvar));
    vector<vector<double> > vk4(numtimes,vector<double>(numvar));
}

</code>```

I'm not quite sure why this call worked in my original(procedural) program, but not in my current program.

答:
With classes, you can't initialize members outside of functions.  You can assign them in the constructor though.

Also, you wrote  "vector" in a bunch of places where you need "std::vector".  This should fix it:

```<code>#include <math.h>
#include <stdio.h>
#include <iostream>
#include <vector>

class RK4 {
   public:
    RK4(double x_i, double y_i, double z_i, double vx_i, double vy_i, double vz_i) {
        double dt = 0.01;
        int numtimes = 1000;

        int numvar = 3;
        double mu = 398589590898200.0;

        //assigning the vectors
        position = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        velocity = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk1 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk2 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk3 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk4 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk1 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk2 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk3 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk4 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
    }
    //time-related stuff
    double dt = 0.01;
    int numtimes = 1000;

    int numvar = 3;
    double mu = 398589590898200.0;

    //declaring vectors
    std::vector<std::vector<double> > position;
    std::vector<std::vector<double> > velocity;
    std::vector<std::vector<double> > rk1;
    std::vector<std::vector<double> > rk2;
    std::vector<std::vector<double> > rk3;
    std::vector<std::vector<double> > rk4;
    std::vector<std::vector<double> > vk1;
    std::vector<std::vector<double> > vk2;
    std::vector<std::vector<double> > vk3;
    std::vector<std::vector<double> > vk4;
};

int main() {
    RK4 r(1, 1, 1, 1, 1, 1);

    return 0;
}
</code>```

Body:
So I have procedurally programmed a way to integrate equations using the Runge-Kutta 4(RK4) method in C++. I am currently trying to create an RK4 class to add more functionality to my program. However, when I set up my 2D arrays in the class, I receive the "C++ requires a type specifier for all declarations" error, that I didn't receive in the original program.

At first, I was using namespace std;, however I came across an answer that said that that was bad programming practice, so I erased that line and called std::vector instead. I also made sure to include the vector library, to no avail.

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>

class RK4 {
public:
    RK4(double x_i, double y_i, double z_i, double vx_i, double vy_i, double vz_i);
    //time-related stuff
    double dt = 0.01;
    int numtimes = 1000;

    int numvar = 3;
    double mu = 398589590898200.0;

    //setting up variables
    std::vector<vector<double> > position(numtimes,vector<double>(numvar));
    std::vector<vector<double> > velocity(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk1(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk2(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk3(numtimes,vector<double>(numvar));
    std::vector<vector<double> > rk4(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk1(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk2(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk3(numtimes,vector<double>(numvar));
    std::vector<vector<double> > vk4(numtimes,vector<double>(numvar));

This is how I constructed the code in my original program, with no problem:

#include <iostream>
#include <ostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
// time related things
    //double t_i = 0; // initial time
    double dt = 0.01; // time step
    int numtimes = 10000; // how many steps taken

    vector<vector<double> > position(numtimes,vector<double>(numvar));
    vector<vector<double> > velocity(numtimes,vector<double>(numvar));

    vector<vector<double> > rk1(numtimes,vector<double>(numvar));
    vector<vector<double> > rk2(numtimes,vector<double>(numvar));
    vector<vector<double> > rk3(numtimes,vector<double>(numvar));
    vector<vector<double> > rk4(numtimes,vector<double>(numvar));
    vector<vector<double> > vk1(numtimes,vector<double>(numvar));
    vector<vector<double> > vk2(numtimes,vector<double>(numvar));
    vector<vector<double> > vk3(numtimes,vector<double>(numvar));
    vector<vector<double> > vk4(numtimes,vector<double>(numvar));
}

I'm not quite sure why this call worked in my original(procedural) program, but not in my current program.

Body:
With classes, you can't initialize members outside of functions.  You can assign them in the constructor though.

Also, you wrote  "vector" in a bunch of places where you need "std::vector".  This should fix it:

#include <math.h>
#include <stdio.h>
#include <iostream>
#include <vector>

class RK4 {
   public:
    RK4(double x_i, double y_i, double z_i, double vx_i, double vy_i, double vz_i) {
        double dt = 0.01;
        int numtimes = 1000;

        int numvar = 3;
        double mu = 398589590898200.0;

        //assigning the vectors
        position = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        velocity = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk1 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk2 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk3 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        rk4 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk1 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk2 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk3 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
        vk4 = std::vector<std::vector<double> >(numtimes, std::vector<double>(numvar));
    }
    //time-related stuff
    double dt = 0.01;
    int numtimes = 1000;

    int numvar = 3;
    double mu = 398589590898200.0;

    //declaring vectors
    std::vector<std::vector<double> > position;
    std::vector<std::vector<double> > velocity;
    std::vector<std::vector<double> > rk1;
    std::vector<std::vector<double> > rk2;
    std::vector<std::vector<double> > rk3;
    std::vector<std::vector<double> > rk4;
    std::vector<std::vector<double> > vk1;
    std::vector<std::vector<double> > vk2;
    std::vector<std::vector<double> > vk3;
    std::vector<std::vector<double> > vk4;
};

int main() {
    RK4 r(1, 1, 1, 1, 1, 1);

    return 0;
}


问:
how to cancel interactively task in dolphindb
When running interactive tasks with GUI in dolphindb, is there any way to cancel the interactive tasks? After running a long-term task, I found that I still need to modify the script to run again. At this time, the running button is no longer available. Is there any other way besides closing and restarting the data nodes?</p>

答: Use function getConsoleJobs to get a list of interactive jobs. Find out the rootJobId of the job you would like to cancel. Then call function cancelConsoleJob to cancel the desired job.


问:
Big O Notation Example Show that N^2 is not O(n)
Show that n^2 is not O(n)

```<code>f(n)=n^2
g(n) = n
c = 1
n_0=2

n^2 <= 1*n for all n_0 >= 2
4 <= 2
4 is not less than or equal to 2. Therefore, n^2 is not O(n).
</code>```

I need to show that NO c works with this, however, the c of 2, with n of 2 will work. How is n^2 not n?

答:
Let's assume that n² is in O(n).

Then there must be a c and a n₀ such that for all n ≥ n₀, n² ≤ c*n (by the definition of O notation).

Let k = max(c, n₀) + 1. By the above property we have k² ≤ c*k (since k > n₀), from which it follows that k ≤ c.

However, k > c by construction. That's a contradiction.

Therefore our assumption is false and n² cannot be in O(n).

Body:
Show that n^2 is not O(n)

f(n)=n^2
g(n) = n
c = 1
n_0=2

n^2 <= 1*n for all n_0 >= 2
4 <= 2
4 is not less than or equal to 2. Therefore, n^2 is not O(n).

I need to show that NO c works with this, however, the c of 2, with n of 2 will work. How is n^2 not n?


问:
Dynamically open and close div on scroll
What I am trying to achieve is that my div, slowly closes as one scrolls down, and then as one scrolls up it should slowly open and expand! I have achieve the first part but i am straggling with the second part, that's is the div is not closing as i scroll up! Please take a look at this Codepen to fully understand!

Below are my snippets!

var img = $('.banner_img_desktop').find('img');
  function isScrolledIntoView(elem) {
      var docViewTop = $(window).scrollTop();
      var docViewBottom = docViewTop + $(window).height();
      var elemTop = $(elem).offset().top;
      var elemBottom = elemTop + $(elem).height();
      return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
  }

  var downScroll = 0;
  var upScroll = 0;
  $(window).scroll(function() {
   var scrollTop = $(window).scrollTop();
   if(this.oldScroll < this.scrollY) {
    console.log("down");
    if (isScrolledIntoView(img)) {
     downScroll = downScroll + 1;
     var elemScroll = downScroll;
     // console.log("elemScroll1", elemScroll);
           var imgPos = (elemScroll / 2) * 10 + 'px';
           console.log("imgPos 1", imgPos);
           img.css('transform', 'translateY(' + imgPos + ')');
           img.css('margin-top', '-' + imgPos);

    }
   }
   else {
    if (isScrolledIntoView(img)) {
     upScroll = upScroll + 1;
     var elemScroll = upScroll;
     console.log("upScroll", upScroll);
           var imgPos = (elemScroll / 2) * 10;
           console.log("upScroll", upScroll);
            img.css('transform', 'translateY(-' + imgPos + 'px)');
            var margin = img.css('margin-top');
            console.log('margin', margin);
            img.css('margin-top', '-' + upScroll - margin + 'px');
    }
   }
         this.oldScroll = this.scrollY;
    });```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.article {
  max-width: 900px;
  margin: auto;
}
h1 {
  text-align: center;
}
.banner {
  position: relative;
  max-width: unset !important;
  margin-left: -20px !important;
  margin-right: -20px !important;
}
.banner .banner_container {
  background-color: #e7e6e4;
}
.banner .banner_container:before, .banner .banner_container:after {
  color: #fff;
  text-align: center;
  display: block;
  width: 100%;
  background-color: #000;
  text-transform: uppercase;
  font: 10px/10px Helvetica, Arial, sans-serif;
  padding: 5px 0px;
}
.banner .banner_container:before {
  content: 'Advertisement';
}
.banner .banner_container:after {
  content: 'Scroll to continue with content';
  position: absolute;
  bottom: 0;
}
.banner .banner_container .banner_content {
  padding-top: 20px;
  padding-bottom: 30px;
  position: relative;
}
.banner .banner_container .banner_content .banner_img_desktop {
  display: block;
}
.banner .banner_container .banner_content .banner_img_desktop figure {
  text-align: center;
  overflow: hidden;
}
.banner .banner_container .banner_content .banner_img_desktop figure img {
  height: 300px;
}</code>```

Header

    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sapien velit, aliquet eget commodo nec, auctor a sapien. Nam eu neque vulputate diam rhoncus faucibus. Curabitur quis varius libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam placerat sem at mauris suscipit porta. Cras metus velit, elementum sed pellentesque a, pharetra eu eros. Etiam facilisis placerat euismod. Nam faucibus neque arcu, quis accumsan leo tincidunt varius. In vel diam enim. Sed id ultrices ligula. Maecenas at urna arcu. Sed quis nulla sapien. Nam felis mauris, tincidunt at ce purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin efficitur, nisi vel finibus elementum, orci sem volutpat eros, eget ultrices velit mi sagittis massa. Vestibulum sagittis ullamcorper cursus. Ut turpis dolor, tempor ut tellus et, soda sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

```

答:
Here are some changes that demonstrate how to proceed. It's certainly far from complete, but the structure is there for you to fiddle with.

The key change was to fix the isScrolledIntoView() test:

```<code>return (elemTop >= docViewBottom);
</code>```

But you also want to stop opening the ad window when it is fully opened (var openup), and reset the vars if the user scrolls past the ad window, etc.

Another puzzle (I haven't solved yet) is that your isScrolled... func should keep track of more than just whether the page has scrolled past the trigger point. It should also keep track of whether the page has passed the bottom of the ad, and the same two questions in reverse if scrolling up. Perhaps this func can also be used to reset the display the ad variables and div height...

var img = $('.banner_img_desktop').find('img');
var ban = $('.banner');
var imgPos=0, multiplier=20, maxheight=300, openup=true;
var lastScroll=0, downScroll=0, upScroll=0, direction='down';
var bodyHeight = $('body').height(), extraOffset=50;

function isScrolledIntoView(elem, direction) {
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();
    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();
$('#msg1').html(docViewBottom +'/'+ elemTop);
$('#msg2').html(elemBottom+' // '+docViewTop);
    if (direction == 'down'){
        if (docViewBottom > bodyHeight){
        //$('#msg2').css('background','red');
           //If return to docTop, reset vars
           imgPos=0;
           openup=true;
           downScroll=0;
           $('.banner').css('height', '40px');
           return false;
        }else{
           return (docViewBottom >= elemTop+extraOffset);
        }
    }else{
        if (docViewTop < 50){
        //$('#msg2').css('background','red');
           //If return to docTop, reset vars
           imgPos=0;
           openup=true;
           downScroll=0;
           $('.banner').css('height', '40px');
        }
        return (elemTop <= docViewBottom);
    }
}

$(window).scroll(function() {
    var scrollTop = $(window).scrollTop();
$('#msg2').html(scrollTop+' // '+lastScroll+' // '+direction);
    if(scrollTop > lastScroll) {
        direction = 'down';
        if (isScrolledIntoView(img, direction)) {
           downScroll += 1;
           if (openup && imgPos <= 300){ //300 is img max height
              imgPos = (downScroll / 2) * multiplier;
              if (imgPos > 300) openup = false;
           }else{
              if (imgPos > 40) imgPos = imgPos - 15;
           }
//$('#msg2').html(imgPos+' // '+downScrol+' // '+direction);
//$('#msg1').html($('#msg1').html() + '[300]');
           $('.banner').css('height', imgPos + 'px');
        }

    } else {

        direction = 'up';
        if (isScrolledIntoView(img, 'up')) {
           last_direction = 'up';
           upScroll += 1;
           if (openup && imgPos <= 300){
              imgPos = (upScroll / 2) * multiplier;
              if (imgPos > 300) openup = false;
           }else{
              imgPos = imgPos - upScroll;
           }
           $('.banner').css('height', imgPos + 'px');
        }
    }
    lastScroll = scrollTop;
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#msg1{position:fixed;top:0; left:0;padding:5px;font-size:1.2rem;background:lavender;border:1px solid blue;z-index:999999;}
#msg2{position:fixed;top:0;right:0;padding:5px;font-size:1.2rem;background:wheat; border:1px solid orange;z-index:999999;}

.article{max-width:900px;margin:auto;}
h1{text-align:center;}

.banner{position:relative;height:40px;max-width:unset !important;margin:0 -20px;overflow:hidden;}

.banner .banner_container{background-color:#e7e6e4;}
.banner .banner_container:before, .banner .banner_container:after{color:#fff;text-align:center;display:block;width:100%;background-color:#000;text-transform:uppercase;font:10px/10px Helvetica, Arial, sans-serif;padding:5px 0px;}
.banner .banner_container:before{content:'Advertisement';}
.banner .banner_container:after{content:'Scroll to continue with content';position:absolute;bottom:0;}
.banner .banner_container .banner_content{padding-top:20px;padding-bottom:30px;position:relative;}
.banner .banner_container .banner_content .banner_img_desktop{display:block;}
.banner .banner_container .banner_content .banner_img_desktop figure{text-align:center;overflow:hidden;}
.banner .banner_container .banner_content .banner_img_desktop figure img{height:300px;}</code>```

Scroll Very Slowly

    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sapien velit, aliquet eget commodo nec, auctor a sapien. Nam eu neque vulputate diam rhoncus faucibus. Curabitur quis varius libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam placerat sem at mauris suscipit porta. Cras metus velit, elementum sed pellentesque a, pharetra eu eros. Etiam facilisis placerat euismod. Nam faucibus neque arcu, quis accumsan leo tincidunt varius. In vel diam enim. Sed id ultrices ligula. Maecenas at urna arcu. Sed quis nulla sapien. Nam felis mauris, tincidunt at ce purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin efficitur, nisi vel finibus elementum, orci sem volutpat eros, eget ultrices velit mi sagittis massa. Vestibulum sagittis ullamcorper cursus. Ut turpis dolor, tempor ut tellus et, soda sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

```

Body:
What I am trying to achieve is that my div, slowly closes as one scrolls down, and then as one scrolls up it should slowly open and expand! I have achieve the first part but i am straggling with the second part, that's is the div is not closing as i scroll up! Please take a look at this Codepen to fully understand!

Below are my snippets!

var img = $('.banner_img_desktop').find('img');
  function isScrolledIntoView(elem) {
      var docViewTop = $(window).scrollTop();
      var docViewBottom = docViewTop + $(window).height();
      var elemTop = $(elem).offset().top;
      var elemBottom = elemTop + $(elem).height();
      return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
  }

  var downScroll = 0;
  var upScroll = 0;
  $(window).scroll(function() {
   var scrollTop = $(window).scrollTop();
   if(this.oldScroll < this.scrollY) {
    console.log("down");
    if (isScrolledIntoView(img)) {
     downScroll = downScroll + 1;
     var elemScroll = downScroll;
     // console.log("elemScroll1", elemScroll);
           var imgPos = (elemScroll / 2) * 10 + 'px';
           console.log("imgPos 1", imgPos);
           img.css('transform', 'translateY(' + imgPos + ')');
           img.css('margin-top', '-' + imgPos);

    }
   }
   else {
    if (isScrolledIntoView(img)) {
     upScroll = upScroll + 1;
     var elemScroll = upScroll;
     console.log("upScroll", upScroll);
           var imgPos = (elemScroll / 2) * 10;
           console.log("upScroll", upScroll);
            img.css('transform', 'translateY(-' + imgPos + 'px)');
            var margin = img.css('margin-top');
            console.log('margin', margin);
            img.css('margin-top', '-' + upScroll - margin + 'px');
    }
   }
         this.oldScroll = this.scrollY;
    });

.article {
  max-width: 900px;
  margin: auto;
}
h1 {
  text-align: center;
}
.banner {
  position: relative;
  max-width: unset !important;
  margin-left: -20px !important;
  margin-right: -20px !important;
}
.banner .banner_container {
  background-color: #e7e6e4;
}
.banner .banner_container:before, .banner .banner_container:after {
  color: #fff;
  text-align: center;
  display: block;
  width: 100%;
  background-color: #000;
  text-transform: uppercase;
  font: 10px/10px Helvetica, Arial, sans-serif;
  padding: 5px 0px;
}
.banner .banner_container:before {
  content: 'Advertisement';
}
.banner .banner_container:after {
  content: 'Scroll to continue with content';
  position: absolute;
  bottom: 0;
}
.banner .banner_container .banner_content {
  padding-top: 20px;
  padding-bottom: 30px;
  position: relative;
}
.banner .banner_container .banner_content .banner_img_desktop {
  display: block;
}
.banner .banner_container .banner_content .banner_img_desktop figure {
  text-align: center;
  overflow: hidden;
}
.banner .banner_container .banner_content .banner_img_desktop figure img {
  height: 300px;
}

Header

    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sapien velit, aliquet eget commodo nec, auctor a sapien. Nam eu neque vulputate diam rhoncus faucibus. Curabitur quis varius libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam placerat sem at mauris suscipit porta. Cras metus velit, elementum sed pellentesque a, pharetra eu eros. Etiam facilisis placerat euismod. Nam faucibus neque arcu, quis accumsan leo tincidunt varius. In vel diam enim. Sed id ultrices ligula. Maecenas at urna arcu. Sed quis nulla sapien. Nam felis mauris, tincidunt at ce purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin efficitur, nisi vel finibus elementum, orci sem volutpat eros, eget ultrices velit mi sagittis massa. Vestibulum sagittis ullamcorper cursus. Ut turpis dolor, tempor ut tellus et, soda sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.

Body:
Here are some changes that demonstrate how to proceed. It's certainly far from complete, but the structure is there for you to fiddle with.

The key change was to fix the isScrolledIntoView() test:

return (elemTop >= docViewBottom);

But you also want to stop opening the ad window when it is fully opened (var openup), and reset the vars if the user scrolls past the ad window, etc.

Another puzzle (I haven't solved yet) is that your isScrolled... func should keep track of more than just whether the page has scrolled past the trigger point. It should also keep track of whether the page has passed the bottom of the ad, and the same two questions in reverse if scrolling up. Perhaps this func can also be used to reset the display the ad variables and div height...

var img = $('.banner_img_desktop').find('img');
var ban = $('.banner');
var imgPos=0, multiplier=20, maxheight=300, openup=true;
var lastScroll=0, downScroll=0, upScroll=0, direction='down';
var bodyHeight = $('body').height(), extraOffset=50;

function isScrolledIntoView(elem, direction) {
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();
    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();
$('#msg1').html(docViewBottom +'/'+ elemTop);
$('#msg2').html(elemBottom+' // '+docViewTop);
    if (direction == 'down'){
        if (docViewBottom > bodyHeight){
        //$('#msg2').css('background','red');
           //If return to docTop, reset vars
           imgPos=0;
           openup=true;
           downScroll=0;
           $('.banner').css('height', '40px');
           return false;
        }else{
           return (docViewBottom >= elemTop+extraOffset);
        }
    }else{
        if (docViewTop < 50){
        //$('#msg2').css('background','red');
           //If return to docTop, reset vars
           imgPos=0;
           openup=true;
           downScroll=0;
           $('.banner').css('height', '40px');
        }
        return (elemTop <= docViewBottom);
    }
}

$(window).scroll(function() {
    var scrollTop = $(window).scrollTop();
$('#msg2').html(scrollTop+' // '+lastScroll+' // '+direction);
    if(scrollTop > lastScroll) {
        direction = 'down';
        if (isScrolledIntoView(img, direction)) {
           downScroll += 1;
           if (openup && imgPos <= 300){ //300 is img max height
              imgPos = (downScroll / 2) * multiplier;
              if (imgPos > 300) openup = false;
           }else{
              if (imgPos > 40) imgPos = imgPos - 15;
           }
//$('#msg2').html(imgPos+' // '+downScrol+' // '+direction);
//$('#msg1').html($('#msg1').html() + '[300]');
           $('.banner').css('height', imgPos + 'px');
        }

    } else {

        direction = 'up';
        if (isScrolledIntoView(img, 'up')) {
           last_direction = 'up';
           upScroll += 1;
           if (openup && imgPos <= 300){
              imgPos = (upScroll / 2) * multiplier;
              if (imgPos > 300) openup = false;
           }else{
              imgPos = imgPos - upScroll;
           }
           $('.banner').css('height', imgPos + 'px');
        }
    }
    lastScroll = scrollTop;
});

#msg1{position:fixed;top:0; left:0;padding:5px;font-size:1.2rem;background:lavender;border:1px solid blue;z-index:999999;}
#msg2{position:fixed;top:0;right:0;padding:5px;font-size:1.2rem;background:wheat; border:1px solid orange;z-index:999999;}

.article{max-width:900px;margin:auto;}
h1{text-align:center;}

.banner{position:relative;height:40px;max-width:unset !important;margin:0 -20px;overflow:hidden;}

.banner .banner_container{background-color:#e7e6e4;}
.banner .banner_container:before, .banner .banner_container:after{color:#fff;text-align:center;display:block;width:100%;background-color:#000;text-transform:uppercase;font:10px/10px Helvetica, Arial, sans-serif;padding:5px 0px;}
.banner .banner_container:before{content:'Advertisement';}
.banner .banner_container:after{content:'Scroll to continue with content';position:absolute;bottom:0;}
.banner .banner_container .banner_content{padding-top:20px;padding-bottom:30px;position:relative;}
.banner .banner_container .banner_content .banner_img_desktop{display:block;}
.banner .banner_container .banner_content .banner_img_desktop figure{text-align:center;overflow:hidden;}
.banner .banner_container .banner_content .banner_img_desktop figure img{height:300px;}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="msg1"></div>
<div id="msg2"></div>
<div class="main">
  <h1>Scroll Very Slowly</h1>
  <div class="article one">
    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
  </div>
<div class="banner">
  <div class="banner_container">
     <div class="banner_content">
        <div class="banner_img_desktop">
           <figure>
              <img src="http://www.ucodice.com/kinglinkr/front/img/banner.png" alt="">
           </figure>
        </div>
     </div>
  </div>
</div>
  <div class="article two">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sapien velit, aliquet eget commodo nec, auctor a sapien. Nam eu neque vulputate diam rhoncus faucibus. Curabitur quis varius libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam placerat sem at mauris suscipit porta. Cras metus velit, elementum sed pellentesque a, pharetra eu eros. Etiam facilisis placerat euismod. Nam faucibus neque arcu, quis accumsan leo tincidunt varius. In vel diam enim. Sed id ultrices ligula. Maecenas at urna arcu. Sed quis nulla sapien. Nam felis mauris, tincidunt at ce purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin efficitur, nisi vel finibus elementum, orci sem volutpat eros, eget ultrices velit mi sagittis massa. Vestibulum sagittis ullamcorper cursus. Ut turpis dolor, tempor ut tellus et, soda sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
    l et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.Vivamus convallis erat in pharetra elementum. Phasellus metus neque, commodo vitae venenatis sed, pellentesque non purus. Pellentesque egestas convallis suscipit. Ut luctus, leo quis porta vulputate, purus purus pellentesque ex, id consequat mi nisl quis eros. Integer ornare libero quis risus fermentum consequat. Mauris pharetra odio sagittis, vulputate magna at, lobortis nulla. Proin eturpis dolor, tempor ut tellus et, sodales ultricies elit. Ut pharetra tristique est ac dictuutrum nulla porta dignissim. Fusce fermentum id nibh laoreet volutpat. Suspendisse venenatis, risus sed euismod finibus, risus arcu fringilla augue, nec vulputate felis nisl et enim. In ornare, massa a cursus cursus, nisl mi ornare mauris, nec porttitor risus erat ut odio. Integer malesuada hendrerit purus ullamcorper molestie. Fusce imperdiet orci vitae purus suscipit rutrum.
  </div>
</div><!-- .main -->


问:
regarding two dimensional arrays
if i have created an array like
int marks[4][2];
then the name of the array must give me the address of the first element,as is in case of one dimensional array,but it is not so?
& also

printf("%d",marks[0]);
&
printf("%d",marks);
 yield the same result?????????

答:
When you use %d in a printf format, the corresponding argument (after default promotions) MUST have type int.  Since you broke that rule in both cases, anything could happen.

marks has type int[4][2] and decays to int(*)[2], which is not int.

marks[0] has type int[2] and decays to int*, which is not int.

(But I'm still surprised an actual implementation would output different addresses.)

Title: regarding two dimensional arrays


问:
Gradle Sync: Wait for the other thread to finish acquiring the distribution never ends
Created new Android Studio project. But Gradle Sync never ends:

Gradle Sync: Wait for the other thread to finish acquiring the
  distribution

I have checked Android Studio does not download data:

I have checked internet connection, it is working but it is slow.

Is this because of a slow internet connection? If no, how to solve this problem?

答:
I also met this problem.
Then I found out that this is due to the gradle of the project dependency is not downloaded.

Ways to verify the problem:

Check if there is a gradle file in the directory.

Linux:~/.gradle/wrapper/dists

Windows:C:\users\{user name}\.gradle\wrapper\dists

If the file does not exist in the directory, Then this is what led.

Ways to resolve the problem:

wo need to download the configuration file manually.

Download the file(gradle) form https://services.gradle.org/distributions/ according to the distributionUrl in the gradle-wrapper.properties, infact You can modify it according to your needs.

For example, in my gradle-wrapper.properties,
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip.
So I should download the filegradle-5.1.1-all.zip

move the file(gradle-5.1.1-all.zip) you downloaded to the deepest part of above directory.

For example, in my pc, its final position is C:\Users\ufan0\.gradle\wrapper\dists\gradle-5.1.1-all\97z1ksx6lirer3kbvdnh7jtjg.

note: There will be undownloaded files in C:\Users\ufan0\.gradle\wrapper\dists\gradle-5.1.1-all\97z1ksx6lirer3kbvdnh7jtjg when you check there first, you can delete them, then move the zip of gradle to there.

Now you can restart the Android Studio, then choose File -> Sync Project With Gradle Files.

When these are all done, The Android Studio should be able to work properly.

note: In order to avoid this type of situation the next time, you can choose to configure the Setting -> Gradle -> Use local gradle distribution.


问:
Unique gmail address on aws cognito
I heard about a scan used against Netflix costumers based on the dots don't matter policy on gmail email addresses. They exploited the fact that e.xample@gmail.com is the same thing as ex.ample@gmail.com for google, but not for netflix. </p>

<p>Now I am building my application based on aws cognito authentication. It does assure that email address is unique, but, like netflix used to do, they do consider the dots. I don't want to be all thinking how someone can potentially exploit that against me, so I would like cognito to consider the "dots doesn't matter" when evaluating uniqueness. How can I do that? </p>

答: With AWS Cognito, you can do a Pre-Signup Lambda Trigger to custom validate the user's signup data before signing them up.</p>

Title: Unique gmail address on aws cognito

Body:
I heard about a scan used against Netflix costumers based on the dots don't matter policy on gmail email addresses. They exploited the fact that e.xample@gmail.com is the same thing as ex.ample@gmail.com for google, but not for netflix.

Now I am building my application based on aws cognito authentication. It does assure that email address is unique, but, like netflix used to do, they do consider the dots. I don't want to be all thinking how someone can potentially exploit that against me, so I would like cognito to consider the "dots doesn't matter" when evaluating uniqueness. How can I do that?


问:
Persist ENV vars across multi-stage Docker builds
Last time I checked, when I did this:

```<code>FROM x:latest
ENV foo 'bar'

FROM y:latest
RUN echo "$foo"
</code>```

then "echo $foo" was empty  - is there a way to persist ENV vars across multi-stage builds?

答:
A build argument might work for you in this case. The user won't be able to override it and it won't be available in the container but other than that I think it fits.

```<code>FROM alpine
ARG FOO
RUN echo first step FOO is $FOO

FROM alpine
ARG FOO
RUN echo second step FOO is $FOO
</code>```

To build you need to pass --build-arg with a value.

```<code>$ docker build --build-arg FOO=bar .
Step 1/6 : FROM alpine
 ---> 055936d39205
Step 2/6 : ARG FOO
 ---> Running in 3f5f18206d06
Removing intermediate container 3f5f18206d06
 ---> 2b82e4b958f7
Step 3/6 : RUN echo first step FOO is $FOO
 ---> Running in c0256dfe286d
first step FOO is bar
Removing intermediate container c0256dfe286d
 ---> 79286b74611f
Step 4/6 : FROM alpine
 ---> 055936d39205
Step 5/6 : ARG FOO
 ---> Running in 9fc20546619f
Removing intermediate container 9fc20546619f
 ---> 30325962d73a
Step 6/6 : RUN echo second step FOO is $FOO
 ---> Running in a8906382909a
second step FOO is bar
Removing intermediate container a8906382909a
 ---> 521dbbfa398b
Successfully built 521dbbfa398b
</code>```

Body:
Last time I checked, when I did this:

FROM x:latest
ENV foo 'bar'

FROM y:latest
RUN echo "$foo"

then "echo $foo" was empty  - is there a way to persist ENV vars across multi-stage builds?

Body:
A build argument might work for you in this case. The user won't be able to override it and it won't be available in the container but other than that I think it fits.

FROM alpine
ARG FOO
RUN echo first step FOO is $FOO

FROM alpine
ARG FOO
RUN echo second step FOO is $FOO

To build you need to pass --build-arg with a value.

$ docker build --build-arg FOO=bar .
Step 1/6 : FROM alpine
 ---> 055936d39205
Step 2/6 : ARG FOO
 ---> Running in 3f5f18206d06
Removing intermediate container 3f5f18206d06
 ---> 2b82e4b958f7
Step 3/6 : RUN echo first step FOO is $FOO
 ---> Running in c0256dfe286d
first step FOO is bar
Removing intermediate container c0256dfe286d
 ---> 79286b74611f
Step 4/6 : FROM alpine
 ---> 055936d39205
Step 5/6 : ARG FOO
 ---> Running in 9fc20546619f
Removing intermediate container 9fc20546619f
 ---> 30325962d73a
Step 6/6 : RUN echo second step FOO is $FOO
 ---> Running in a8906382909a
second step FOO is bar
Removing intermediate container a8906382909a
 ---> 521dbbfa398b
Successfully built 521dbbfa398b


问:
View PDFs with forms in Firefox
I am working on a web application and there is a need to preview PDF in Firefox.

Obviously I have embedded the PDF in the HTML code. The problem is that these PDFs contain forms and I know that the built-in Firefox viewer cannot display forms. Except the forms (which contain digital signatures) the rest of the document is displayed properly and in Chrome everything works fine (displaying the signatures too).

I want to ask which is the best approach to support the view of the whole document in Firefox. The current version I am working on is 52.7.3 but I want to do the system scalable for future versions.

I was thinking of transforming the PDF into a Base64 String and embed like that but trying this with some online demos did not work either (maybe the document is quite big?).

The other posibility I was thinking of, is transforming the PDF in JPEG (or similar format) and preview like that. What do you think about that?

Is there any library to handle PDF files from Java/Javascript code that does not use embedded viewers? I tried PDF.js but I realised that it is using the built in viewers. Correct me on this If I am wrong.

答:
```<code>Desktop.open(File)
</code>```

You can use this to open the PDF file if the file does not have to be opened with Firefox.

Title: View PDFs with forms in Firefox

Body:
Desktop.open(File)

You can use this to open the PDF file if the file does not have to be opened with Firefox.


问:
How to create multi product for a specific id
I am new to cosmos db and I am creating a web api project base on cosmos db .I created the basic crud operation. Now the problem one  is vendor has more industry ,in industry vendor may have more than one product .I create one product ,when i try to create more the one ,it show  the error id already used . Here i used the id as partition key .
Problem two is some vendor may have only category only so i need to add the product directly to them .
please help me to structure it solve the problem .
 Addproduct code:

```<code> public async Task<Catalog> AddProduct(
          Catalog order)
        {
            var requestOptions =
                new RequestOptions
                {
                    PartitionKey = new PartitionKey(order.Id.ToString())
                };

            var catalogDocument = await _cosmosClient.CreateDocumentAsync(
                UriFactory.CreateDocumentCollectionUri(
                    _azureCosmosDbOptions.Value.DatabaseId, "catalog"), order, requestOptions);

            return
                (Catalog)((dynamic)catalogDocument.Resource);
        }

</code>```

My json code :

```<code>    "id": "8000003c-0001-fb00-b63f-84710c7967aa",

    "industy": {

      "category": [
        {

          "subcategory": [
            {
                product1,product2.....
                }
</code>```

error message :
{"code":409,"body":{"code":"Conflict","message":"Entity with the specified id already exists in the system}

答: You shouldn't have a single giant document for everything like this. Use a separate collection and save each product as a separate document with the vendor, industry and category as fields on that document. Then you can modify individual product records easily and retrieve all products for a given vendor or category in a query.

Body:
I am new to cosmos db and I am creating a web api project base on cosmos db .I created the basic crud operation. Now the problem one  is vendor has more industry ,in industry vendor may have more than one product .I create one product ,when i try to create more the one ,it show  the error id already used . Here i used the id as partition key .
Problem two is some vendor may have only category only so i need to add the product directly to them .
please help me to structure it solve the problem .
 Addproduct code:

 public async Task<Catalog> AddProduct(
          Catalog order)
        {
            var requestOptions =
                new RequestOptions
                {
                    PartitionKey = new PartitionKey(order.Id.ToString())
                };

            var catalogDocument = await _cosmosClient.CreateDocumentAsync(
                UriFactory.CreateDocumentCollectionUri(
                    _azureCosmosDbOptions.Value.DatabaseId, "catalog"), order, requestOptions);

            return
                (Catalog)((dynamic)catalogDocument.Resource);
        }

My json code :

    "id": "8000003c-0001-fb00-b63f-84710c7967aa",

    "industy": {

      "category": [
        {

          "subcategory": [
            {
                product1,product2.....
                }

error message :
{"code":409,"body":{"code":"Conflict","message":"Entity with the specified id already exists in the system}