问:
Can't hide soft input keyboard -- getWindowToken() always null
I have an Activity with Tabs set up with a ViewPager, in one of the Fragments there's an EditText which opens soft input keyboard when the Activity starts, which isn't something I want. I've been trying to hide it but when I'm trying to get a WindowToken it's always null -- on the EditText itself, on the root view of the Fragment, on the ContentView of the parent activity (I tried findViewById(android.R.id.content) with and without getDecorView(), with and without getRootView()), on every View I get from ContentView with getChildAt(). getCurrentFocus() also returns null.
Also, I tried getting the parent Activity both from getActivity() and from a reference I keep in my Application class, and they work the same.

My ultimate goal is to hide the keyboard, or not show it at all unless the user explicitly calls it. If I have to find a way to get a WindowToken for that, I'd like to do that, but if there's another way to hide the keyboard, I'll be happy to try that too.

I'd like to know why the question was downvoted. I can't improve it if I don't know the reason.

Bits of related code:

activity_main.xml:

```<code><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"
    android:fitsSystemWindows="true"
    android:background="@color/windowBackground"
    tools:openDrawer="start">

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

<include
    layout="@layout/drawer" />

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

app_bar_main.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"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.app.activities.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    android:theme="@style/AppTheme.AppBarOverlay">

    ...

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/underline_grey"
        app:tabMode="scrollable"
        app:tabGravity="center"
        app:popupTheme="@style/AppTheme.PopupOverlayBg"/>

</android.support.design.widget.AppBarLayout>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:scrollbars="vertical"
    android:orientation="vertical"
    app:layout_anchor="@+id/appbar_layout"
    android:fillViewport="true">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            layout="@layout/bg"
            android:layout_width="match_parent"
            android:layout_height="800dp" />
    <include
        android:id="@+id/pager_frame"
        layout="@layout/content_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/></FrameLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
</code>```

(before anyone says anything, the Scroll wasn't my idea)

content_main.xml:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.company.app.activities.MainActivity"
tools:showIn="@layout/app_bar_main">

<android.support.v4.view.ViewPager
    android:id="@+id/main_page_pager"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
</code>```

fragment_get_bonuses.xml:

```<code><android.support.constraint.ConstraintLayout
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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical"
android:gravity="center"
tools:context="com.company.app.fragments.GetBonusesFragment">

...

<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline50"
app:layout_constraintBottom_toTopOf="@+id/guideline70"
card_view:contentPadding="4dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="10dp"
card_view:cardBackgroundColor="@color/windowBackground"
android:layout_span="6">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="4dp"
    android:gravity="center"
    android:weightSum="1">
    <EditText
        android:id="@+id/bonuses_code_edit"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_weight=".5"
        android:padding="8dp"
        android:layout_marginRight="4dp"
        android:background="@drawable/border_grey"
        android:hint="xxxx-xxxx-xxxx"
        android:maxLines="1"
        android:lines="1"
        android:inputType="text"
        android:nextFocusForward="@+id/bonuses_code_card"/>
    <android.support.v7.widget.CardView
        android:id="@+id/bonuses_code_card"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="4dp"
        card_view:contentPadding="0dp"
        card_view:cardUseCompatPadding="false"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="10dp"
        card_view:cardBackgroundColor="@color/pinkAcivateCode"
        android:layout_weight=".5"
        android:clickable="true"
        android:onClick="onMenuButtonsClick">
        <TextView
            android:id="@+id/bonuses_code_button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/activate_code"
            android:textColor="@color/textColorPrimary"
            android:lines="2"
            android:padding="8dp" />
    </android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
...

<android.support.constraint.Guideline
android:id="@+id/guideline50"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />

<android.support.constraint.Guideline
android:id="@+id/guideline70"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.7"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />

...

</android.support.constraint.ConstraintLayout>
</code>```

MainActivity.java:

```<code>public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

AppCompatActivity context;

...

TabLayout mainPageTabs;

View pagerView;
ViewPager mainPagePager;
MainPageTabsAdapter adapter;

TextView tabBonuses;
...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fresco.initialize(this);
    setContentView(R.layout.activity_main);
    context = this;
    App.getContext().setCurrent(context); // saves reference to currently running Activity in Application class
    ...

    pagerView = findViewById(R.id.pager_frame);
    mainPageTabs = (TabLayout) findViewById(R.id.tabs);
    ...
    setupMainTabs();
}

public void setupMainTabs(){
    if (mainPagePager == null) mainPagePager = (ViewPager) findViewById(R.id.main_page_pager);
    if (mainPageTabs == null) mainPageTabs = (TabLayout) findViewById(R.id.tabs);
    setupMainPageViewPager(mainPagePager);
    mainPageTabs.setupWithViewPager(mainPagePager,true);
    ...

    tabBonuses = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_item, null); // TextView with a background
    tabBonuses.setText(getText(R.string.collect_bonuses));
    ...
    mainPageTabs.getTabAt(0).setCustomView(tabBonuses);
    ...
//        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.hideSoftInputFromWindow(findViewById(R.id.pager_frame).getWindowToken(), 0);
}

private void setupMainPageViewPager(ViewPager viewPager) {
    adapter = new MainPageTabsAdapter(getSupportFragmentManager(),this);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(2);
}

...

@Override
protected void onResume() {
    super.onResume();
    App.getContext().setCurrent(context);
    ...
//        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.hideSoftInputFromWindow(findViewById(R.id.pager_frame).getWindowToken(), 0);
}

...
</code>```

}

Application class:

```<code>...
private static App context;
private AppCompatActivity current;
...
@Override
public void onCreate() {
    super.onCreate();
    if (context == null) context = (DreamClub) getApplicationContext();
    ...
}
...

public void setCurrent(AppCompatActivity a) {
    current = a;
}

public Activity getCurrent(){return current;}
...

public static App getContext() {
    if (context == null) context = new DreamClub();
    return context;
}
</code>```

MainPageTabsAdapter.java:

```<code>public class MainPageTabsAdapter extends FragmentPagerAdapter {

Context context;

ArrayList<Fragment> fragmList;
ArrayList<String> titleList;

public MainPageTabsAdapter(FragmentManager fm, Context context) {
    super(fm);
    this.context = context;
    fragmList = new ArrayList<>();
    fragmList.add(new GetBonusesFragment());
    ...
    titleList = new ArrayList<>();
    titleList.add(context.getString(R.string.collect_bonuses));
    ...
}

@Override
public Fragment getItem(int position) {
    return fragmList.get(position);
}

...

@Override
public CharSequence getPageTitle(int position) {
    return titleList.get(position);
}
}
</code>```

GetBonusesFragment.java:

```<code>public class GetBonusesFragment extends Fragment {

EditText codeEdit;
View root;

...

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.fragment_get_bonuses, container, false);
    ...
    codeEdit = (EditText) root.findViewById(R.id.bonuses_code_edit);
//        InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//        codeEdit.requestFocus();
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
    ...
//        codeEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                if (hasFocus) {
//                    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                    imm.showSoftInput(root,0)/*hideSoftInputFromWindow(root.getWindowToken(), 0)*/;
//                }
//                else {
//                    Log.v("!!!called","on focus change: false");
//                    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                    imm.hideSoftInputFromWindow(root.getWindowToken(), 0);
//                }
//            }
//        });
    ...
    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY,0);
//        try {
//            InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//            imm.hideSoftInputFromWindow(DreamClub.getContext().getCurrent().getCurrentFocus().getWindowToken(), 0);
//        }
//        catch (Exception e) {
//            try {
//                InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                imm.hideSoftInputFromWindow(DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView().getWindowToken(), 0);
//            }
//            catch (Exception e1) {
//                if (DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView() != null && ((ViewGroup)getActivity().getWindow().findViewById(android.R.id.content).getRootView()).getChildCount() > 0) {
//                    for (int i = 0; i < ((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildCount(); i++) {
//                        if (((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildAt(i).getWindowToken() != null) {
//                            InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                            imm.hideSoftInputFromWindow(((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildAt(i).getWindowToken(), 0);
//                            break;
//                        }
//                    }
//                }
//            }
//        }
//        root.findViewById(codeEdit.getNextFocusForwardId()).requestFocus();
//        root.findViewById(R.id.bonuses_wallets).requestFocus();
//        if (codeEdit.hasFocus()) {
//            codeEdit.clearFocus();
//        }
//        InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
//        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    return root;
}

//    @Override
//    public void onResume() {
//        super.onResume();
//        InputMethodManager imm = (InputMethodManager)(DreamClub.getContext().getCurrent().getSystemService(Context.INPUT_METHOD_SERVICE));
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
//    }
}
</code>```

答:
Just add this in your manifest activity

android:windowSoftInputMode="stateHidden"

```<code><activity
            android:name=".activity.SignupActivity"

            android:windowSoftInputMode="stateHidden" />
</code>```

Body:
I have an Activity with Tabs set up with a ViewPager, in one of the Fragments there's an EditText which opens soft input keyboard when the Activity starts, which isn't something I want. I've been trying to hide it but when I'm trying to get a WindowToken it's always null -- on the EditText itself, on the root view of the Fragment, on the ContentView of the parent activity (I tried findViewById(android.R.id.content) with and without getDecorView(), with and without getRootView()), on every View I get from ContentView with getChildAt(). getCurrentFocus() also returns null.
Also, I tried getting the parent Activity both from getActivity() and from a reference I keep in my Application class, and they work the same.

My ultimate goal is to hide the keyboard, or not show it at all unless the user explicitly calls it. If I have to find a way to get a WindowToken for that, I'd like to do that, but if there's another way to hide the keyboard, I'll be happy to try that too.

I'd like to know why the question was downvoted. I can't improve it if I don't know the reason.

Bits of related code:

activity_main.xml:

<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"
    android:fitsSystemWindows="true"
    android:background="@color/windowBackground"
    tools:openDrawer="start">

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

<include
    layout="@layout/drawer" />

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

app_bar_main.xml:

<?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"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.app.activities.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    android:theme="@style/AppTheme.AppBarOverlay">

    ...

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/underline_grey"
        app:tabMode="scrollable"
        app:tabGravity="center"
        app:popupTheme="@style/AppTheme.PopupOverlayBg"/>

</android.support.design.widget.AppBarLayout>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:scrollbars="vertical"
    android:orientation="vertical"
    app:layout_anchor="@+id/appbar_layout"
    android:fillViewport="true">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            layout="@layout/bg"
            android:layout_width="match_parent"
            android:layout_height="800dp" />
    <include
        android:id="@+id/pager_frame"
        layout="@layout/content_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/></FrameLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>

(before anyone says anything, the Scroll wasn't my idea)

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.company.app.activities.MainActivity"
tools:showIn="@layout/app_bar_main">

<android.support.v4.view.ViewPager
    android:id="@+id/main_page_pager"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

fragment_get_bonuses.xml:

<android.support.constraint.ConstraintLayout
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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical"
android:gravity="center"
tools:context="com.company.app.fragments.GetBonusesFragment">

...

<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline50"
app:layout_constraintBottom_toTopOf="@+id/guideline70"
card_view:contentPadding="4dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="10dp"
card_view:cardBackgroundColor="@color/windowBackground"
android:layout_span="6">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="4dp"
    android:gravity="center"
    android:weightSum="1">
    <EditText
        android:id="@+id/bonuses_code_edit"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_weight=".5"
        android:padding="8dp"
        android:layout_marginRight="4dp"
        android:background="@drawable/border_grey"
        android:hint="xxxx-xxxx-xxxx"
        android:maxLines="1"
        android:lines="1"
        android:inputType="text"
        android:nextFocusForward="@+id/bonuses_code_card"/>
    <android.support.v7.widget.CardView
        android:id="@+id/bonuses_code_card"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="4dp"
        card_view:contentPadding="0dp"
        card_view:cardUseCompatPadding="false"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="10dp"
        card_view:cardBackgroundColor="@color/pinkAcivateCode"
        android:layout_weight=".5"
        android:clickable="true"
        android:onClick="onMenuButtonsClick">
        <TextView
            android:id="@+id/bonuses_code_button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/activate_code"
            android:textColor="@color/textColorPrimary"
            android:lines="2"
            android:padding="8dp" />
    </android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
...

<android.support.constraint.Guideline
android:id="@+id/guideline50"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />

<android.support.constraint.Guideline
android:id="@+id/guideline70"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.7"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />

...

</android.support.constraint.ConstraintLayout>

MainActivity.java:

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

AppCompatActivity context;

...

TabLayout mainPageTabs;

View pagerView;
ViewPager mainPagePager;
MainPageTabsAdapter adapter;

TextView tabBonuses;
...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fresco.initialize(this);
    setContentView(R.layout.activity_main);
    context = this;
    App.getContext().setCurrent(context); // saves reference to currently running Activity in Application class
    ...

    pagerView = findViewById(R.id.pager_frame);
    mainPageTabs = (TabLayout) findViewById(R.id.tabs);
    ...
    setupMainTabs();
}

public void setupMainTabs(){
    if (mainPagePager == null) mainPagePager = (ViewPager) findViewById(R.id.main_page_pager);
    if (mainPageTabs == null) mainPageTabs = (TabLayout) findViewById(R.id.tabs);
    setupMainPageViewPager(mainPagePager);
    mainPageTabs.setupWithViewPager(mainPagePager,true);
    ...

    tabBonuses = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_item, null); // TextView with a background
    tabBonuses.setText(getText(R.string.collect_bonuses));
    ...
    mainPageTabs.getTabAt(0).setCustomView(tabBonuses);
    ...
//        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.hideSoftInputFromWindow(findViewById(R.id.pager_frame).getWindowToken(), 0);
}

private void setupMainPageViewPager(ViewPager viewPager) {
    adapter = new MainPageTabsAdapter(getSupportFragmentManager(),this);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(2);
}

...

@Override
protected void onResume() {
    super.onResume();
    App.getContext().setCurrent(context);
    ...
//        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.hideSoftInputFromWindow(findViewById(R.id.pager_frame).getWindowToken(), 0);
}

...

}

Application class:

...
private static App context;
private AppCompatActivity current;
...
@Override
public void onCreate() {
    super.onCreate();
    if (context == null) context = (DreamClub) getApplicationContext();
    ...
}
...

public void setCurrent(AppCompatActivity a) {
    current = a;
}

public Activity getCurrent(){return current;}
...

public static App getContext() {
    if (context == null) context = new DreamClub();
    return context;
}

MainPageTabsAdapter.java:

public class MainPageTabsAdapter extends FragmentPagerAdapter {

Context context;

ArrayList<Fragment> fragmList;
ArrayList<String> titleList;

public MainPageTabsAdapter(FragmentManager fm, Context context) {
    super(fm);
    this.context = context;
    fragmList = new ArrayList<>();
    fragmList.add(new GetBonusesFragment());
    ...
    titleList = new ArrayList<>();
    titleList.add(context.getString(R.string.collect_bonuses));
    ...
}

@Override
public Fragment getItem(int position) {
    return fragmList.get(position);
}

...

@Override
public CharSequence getPageTitle(int position) {
    return titleList.get(position);
}
}

GetBonusesFragment.java:

public class GetBonusesFragment extends Fragment {

EditText codeEdit;
View root;

...

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.fragment_get_bonuses, container, false);
    ...
    codeEdit = (EditText) root.findViewById(R.id.bonuses_code_edit);
//        InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//        codeEdit.requestFocus();
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
    ...
//        codeEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                if (hasFocus) {
//                    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                    imm.showSoftInput(root,0)/*hideSoftInputFromWindow(root.getWindowToken(), 0)*/;
//                }
//                else {
//                    Log.v("!!!called","on focus change: false");
//                    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                    imm.hideSoftInputFromWindow(root.getWindowToken(), 0);
//                }
//            }
//        });
    ...
    InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY,0);
//        try {
//            InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//            imm.hideSoftInputFromWindow(DreamClub.getContext().getCurrent().getCurrentFocus().getWindowToken(), 0);
//        }
//        catch (Exception e) {
//            try {
//                InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                imm.hideSoftInputFromWindow(DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView().getWindowToken(), 0);
//            }
//            catch (Exception e1) {
//                if (DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView() != null && ((ViewGroup)getActivity().getWindow().findViewById(android.R.id.content).getRootView()).getChildCount() > 0) {
//                    for (int i = 0; i < ((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildCount(); i++) {
//                        if (((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildAt(i).getWindowToken() != null) {
//                            InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//                            imm.hideSoftInputFromWindow(((ViewGroup)DreamClub.getContext().getCurrent().getWindow().findViewById(android.R.id.content).getRootView()).getChildAt(i).getWindowToken(), 0);
//                            break;
//                        }
//                    }
//                }
//            }
//        }
//        root.findViewById(codeEdit.getNextFocusForwardId()).requestFocus();
//        root.findViewById(R.id.bonuses_wallets).requestFocus();
//        if (codeEdit.hasFocus()) {
//            codeEdit.clearFocus();
//        }
//        InputMethodManager imm = (InputMethodManager)(getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
//        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    return root;
}

//    @Override
//    public void onResume() {
//        super.onResume();
//        InputMethodManager imm = (InputMethodManager)(DreamClub.getContext().getCurrent().getSystemService(Context.INPUT_METHOD_SERVICE));
//        imm.hideSoftInputFromWindow(codeEdit.getWindowToken(), 0);
//    }
}

Body:
Just add this in your manifest activity

android:windowSoftInputMode="stateHidden"

<activity
            android:name=".activity.SignupActivity"

            android:windowSoftInputMode="stateHidden" />


来源: stackexchange

问:
use jquery in angular js function is not working?
I am trying to just write jquery inside angularjs function.but don't know why it is not working?

HTML

```<code><div>
   <span ng-repeat="image in post.postImages" ng-if="$index <= 3" ng-init="image.showDeleteIcon= false" ng-mouseover="image.showDeleteIcon=true" ng-mouseleave="image.showDeleteIcon=false">
   <span ng-if="$index == 3" ng-init="setImgCounter(post.postImages.length,$parent.$index+''+$index)"></span>
   <a id="{{$parent.$index}}{{$index}}" onclick="SetDataGallery(this.id)" ng-href="../upload/post-photos/{{image.attachmentURL}}">
   <img class="img-responsive feed-photo" ng-src="../upload/post-photos/{{image.attachmentURL}}" alt="Photo" style="display:inline;">
   <a href="#" class="imgDelete" ng-if="post.timelineStrore.hasControl" ng-show="image.showDeleteIcon" title="Delete Photo" ng-click="DeletePostAttachment(post.timelineStrore.id, image.postAttachmentId,'image')">
   <i class="fa fa-close"></i>
   </a>
   </a>
   </span>
</div>
</code>```

JS

```<code>$scope.setImgCounter = function (counter,id)
{
    $("#" + id + " img:first-child").css("opacity", "0.5");
}
</code>```

but its not working?

I also tried using =>

```<code>.att('style','opacity:0.5');
</code>```

答:
Use ng-class for dynamically changing css using angularjs. This will allow you to dynamically set classes.

I assume you have your classes defined in a style-sheet that is loaded into memory.

```<code>.white{
    color: #ffffff;
}
.black{
    color: #000000;
}
</code>```

In your angular controller you can have a variable defined that will hold your class-name. Here I am setting it to apply 'white' by default.

```<code>$scope.myClass = "white";
</code>```

Then in your markup you simply bind that variable to your element with ng-class.

```<code><div ng-class="myClass">....</div>
</code>```

Now, whenever $scope.myclass changes the appropriate class will be added to the div and the old class will be removed. So, in your controller you'll have something that will trigger a change...

```<code>if( some_condition ){
    $scope.myClass = "black";
} else {
    $scope.myClass = "white";
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am trying to just write jquery inside angularjs function.but don't know why it is not working?

HTML

   <span ng-repeat="image in post.postImages" ng-if="$index <= 3" ng-init="image.showDeleteIcon= false" ng-mouseover="image.showDeleteIcon=true" ng-mouseleave="image.showDeleteIcon=false">

JS

$scope.setImgCounter = function (counter,id)
{
    $("#" + id + " img:first-child").css("opacity", "0.5");
}

but its not working?

I also tried using =>

.att('style','opacity:0.5');

Body:
Use ng-class for dynamically changing css using angularjs. This will allow you to dynamically set classes.

I assume you have your classes defined in a style-sheet that is loaded into memory.

.white{
    color: #ffffff;
}
.black{
    color: #000000;
}

In your angular controller you can have a variable defined that will hold your class-name. Here I am setting it to apply 'white' by default.

$scope.myClass = "white";

Then in your markup you simply bind that variable to your element with ng-class.

<div ng-class="myClass">....</div>

Now, whenever $scope.myclass changes the appropriate class will be added to the div and the old class will be removed. So, in your controller you'll have something that will trigger a change...

if( some_condition ){
    $scope.myClass = "black";
} else {
    $scope.myClass = "white";
}


问:
Multiline editing in Visual Studio Code
Is it possible to enable multiline editing like in Sublime Text?

For example, press Ctrl to place additional cursor carets and being able to write/delete on multiple places in the document at one time.

答:
From the version 1.13 (May 2017) you can finally change the default modifier key for creating multiple cursors (add to settings):

```<code>"editor.multiCursorModifier": "ctrlCmd"
</code>```

P.S.: The modifier "follow link" from this moment will be Alt.

ContentLicense: CC BY-SA 4.0

Title: Multiline editing in Visual Studio Code

Body:
From the version 1.13 (May 2017) you can finally change the default modifier key for creating multiple cursors (add to settings):

"editor.multiCursorModifier": "ctrlCmd"

P.S.: The modifier "follow link" from this moment will be Alt.


问:
Can't build todo_ddc project
I want to try polymerize so I have found and use that post. But I met issues when try command

```<code>pub run polymerize:polymerize build
</code>```

It works some time and then return bazel's error:

```<code>2017.35.08 16:35:06.015 polymerize      [INFO]: Running bazel ...
____Loading package:
ERROR: while parsing ':all': error loading package '': Encountered error while reading extension file 'BUILD.test_app.bzl': no such package '@build_files//': No WORKSPACE file found in /private/var/tmp/_bazel_kelegorm/df7a1dbca8a607bc3485e726bb483b2b/external/build_files.
</code>```

How can I solve that problem? Why it happens? Why I can't find any mention about that error? What have I missed?

Thanks!

答:
There was a problem with newest bazel versions. Just upgrade to latest polymerize (v. 0.8.6+1)  and it should work again.

To start from a clean workspace just do a :

```<code>git clone git@github.com:polymer-dart/todo_ddc.git
cd todo_ddc
pub get
pub run polymerize:polymerize build
</code>```

Title: Can't build todo_ddc project

Body:
I want to try polymerize so I have found and use that post. But I met issues when try command

pub run polymerize:polymerize build

It works some time and then return bazel's error:

2017.35.08 16:35:06.015 polymerize      [INFO]: Running bazel ...
____Loading package:
ERROR: while parsing ':all': error loading package '': Encountered error while reading extension file 'BUILD.test_app.bzl': no such package '@build_files//': No WORKSPACE file found in /private/var/tmp/_bazel_kelegorm/df7a1dbca8a607bc3485e726bb483b2b/external/build_files.

How can I solve that problem? Why it happens? Why I can't find any mention about that error? What have I missed?

Thanks!

Body:
There was a problem with newest bazel versions. Just upgrade to latest polymerize (v. 0.8.6+1)  and it should work again.

To start from a clean workspace just do a :

git clone git@github.com:polymer-dart/todo_ddc.git
cd todo_ddc
pub get
pub run polymerize:polymerize build


问:
What --server do I use on meteor build <build-output-directory> --server=<host>:<port>?
I'm trying to build my app for Android and I believe it is not connecting to the proper server when I build it. I'm hosting it in AWS and it works in the browser from that site.

```<code> meteor build <build-output-directory> --server=<host>:<port>
</code>```

I've tried using the domain without the port, and the static IP address.

答:
Meteor appears to be having a problem assigning ROOT_URL in the build process when building for mobile. @MasterAM pointed me to this thread where I found the following work around:

```<code>meteor run android-device --mobile-server http://whatever.com:3000
meteor build ../apk --server http://whatever.com:3000
</code>```

The first line sets ROOT_URL references that remain active during the build process.

HTTPS does matter as well.

Body:
I'm trying to build my app for Android and I believe it is not connecting to the proper server when I build it. I'm hosting it in AWS and it works in the browser from that site.

 meteor build <build-output-directory> --server=<host>:<port>

I've tried using the domain without the port, and the static IP address.

Body:
Meteor appears to be having a problem assigning ROOT_URL in the build process when building for mobile. @MasterAM pointed me to this thread where I found the following work around:

meteor run android-device --mobile-server http://whatever.com:3000
meteor build ../apk --server http://whatever.com:3000

The first line sets ROOT_URL references that remain active during the build process.

HTTPS does matter as well.


Title: T-SQL How to get rows for each 5 minutes from the minutes set

Body:
I have this kind of data in the table.

What I need to get somehow not all rows but rows with interval of 5 minutes
in order to reduce their quantity.

Is it possible to do in simple way with T-SQL?

ID    AtTime                  Speed  Label
-------------------------------------------------------------------------
217   2017-06-06 08:01:01.000   0    Lat: 54.3956 Lon: 86.79349
217   2017-06-06 08:01:23.000   0    Lat: 54.3956 Lon: 86.7935
221   2017-06-06 08:04:20.000   0    Lat: 54.39548 Lon: 86.79372
217   2017-06-06 08:06:24.000   0    Lat: 54.39559 Lon: 86.79347
221   2017-06-06 08:09:21.000   0    Lat: 54.39548 Lon: 86.79372
217   2017-06-06 08:11:25.000   0    Lat: 54.3956 Lon: 86.79346
221   2017-06-06 08:12:21.000   0    Lat: 54.39526 Lon: 86.79405
221   2017-06-06 08:12:30.000   0    Lat: 54.39507 Lon: 86.79451
221   2017-06-06 08:12:36.000   14,4    Lat: 54.39503 Lon: 86.79493
221   2017-06-06 08:12:47.000   10,8    Lat: 54.39518 Lon: 86.79536
221   2017-06-06 08:12:56.000   7,2  Lat: 54.39527 Lon: 86.79578
221   2017-06-06 08:13:06.000   7,2  Lat: 54.39529 Lon: 86.79622
221   2017-06-06 08:14:10.000   0    Lat: 54.39545 Lon: 86.79621

Body:
I hope this meets your needs - we first create a CTE that identifies each of the five minute blocks within your data set. We then use a second CTE to pick the earliest row within each block. I wasn't sure whether ID should be used as a second partitioning criterion but I've marked where that could be added:

declare @t table (ID int not null, AtTime datetime not null, Speed decimal(9,4)  not null,
                  Label varchar(29) not null)
insert into @t(ID,AtTime,Speed,Label) values
(217,'2017-06-06T08:01:01.000',0   ,'Lat: 54.3956 Lon: 86.79349 '),
(217,'2017-06-06T08:01:23.000',0   ,'Lat: 54.3956 Lon: 86.7935  '),
(221,'2017-06-06T08:04:20.000',0   ,'Lat: 54.39548 Lon: 86.79372'),
(217,'2017-06-06T08:06:24.000',0   ,'Lat: 54.39559 Lon: 86.79347'),
(221,'2017-06-06T08:09:21.000',0   ,'Lat: 54.39548 Lon: 86.79372'),
(217,'2017-06-06T08:11:25.000',0   ,'Lat: 54.3956 Lon: 86.79346 '),
(221,'2017-06-06T08:12:21.000',0   ,'Lat: 54.39526 Lon: 86.79405'),
(221,'2017-06-06T08:12:30.000',0   ,'Lat: 54.39507 Lon: 86.79451'),
(221,'2017-06-06T08:12:36.000',14.4,'Lat: 54.39503 Lon: 86.79493'),
(221,'2017-06-06T08:12:47.000',10.8,'Lat: 54.39518 Lon: 86.79536'),
(221,'2017-06-06T08:12:56.000',7.2 ,'Lat: 54.39527 Lon: 86.79578'),
(221,'2017-06-06T08:13:06.000',7.2 ,'Lat: 54.39529 Lon: 86.79622'),
(221,'2017-06-06T08:14:10.000',0   ,'Lat: 54.39545 Lon: 86.79621')

;With Times as (
    select distinct u.StartBlock,DATEADD(minute,5,u.StartBlock) as EndBlock
    from @t
        cross apply
        (select DATEADD(minute,((DATEDIFF(minute,0,AtTime)/5)*5),0) as StartBlock) u
), Ordered as (
    select
        *,
        ROW_NUMBER() OVER (PARTITION BY StartBlock /* And ID? */ ORDER BY AtTime) as rn
    from
        @t t
            inner join
        Times tm
            on
                tm.StartBlock <= t.AtTime and
                t.AtTime < tm.EndBlock
)
select *
from Ordered
where rn = 1

Result:

ID          AtTime                  Speed   Label                         StartBlock              EndBlock                rn
----------- ----------------------- ------- ----------------------------- ----------------------- ----------------------- --
217         2017-06-06 08:01:01.000 0.0000  Lat: 54.3956 Lon: 86.79349    2017-06-06 08:00:00.000 2017-06-06 08:05:00.000 1
217         2017-06-06 08:06:24.000 0.0000  Lat: 54.39559 Lon: 86.79347   2017-06-06 08:05:00.000 2017-06-06 08:10:00.000 1
217         2017-06-06 08:11:25.000 0.0000  Lat: 54.3956 Lon: 86.79346    2017-06-06 08:10:00.000 2017-06-06 08:15:00.000 1

Note that this doesn't guarantee that all rows are at least 5 minutes apart. In pathological cases you may have two rows which are in fact only instants apart (e.g. if a particular 5 minute interval only has a single row and it's at the last possible instant in that interval, and the next interval has a row which occurs at exactly the start point). For normal distributions of data though, the data should on average by five minutes apart.


问:
NameError: uninitialized constant Order::AASM
I am implement a order system with AASM, but when I use rails c to check the function, but something wrong happen. NameError: uninitialized constant Order::AASM

There is gem 'aasm' in the Gemfile.
I have searched Google and StackOverflow with NameError: uninitialized constant Order::AASM, but got nothing that did work.

I have reload bundle install and rails s, even reboot the computer.
This is my code.

order's gist is here.

How to fix this?
And if I can't find the right question, or you need more information, could you point it?

答:
Try this:

Comment out gem 'spring'and gem 'spring-watcher-listen', '~> 2.0.0'

Run bundle install

Or try upgrading spring in your project:

In your gemfile gem 'spring', '~> 2.0', '>= 2.0.2'

Run bundle update spring


问:
HTML5 - How to get the center point of SVG text element?
I've got problem with SVG text element. I want to find the center point of SVG text. In HTML file:

```<code><svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <text x="300" y="300" style="font-size: 80px;" id="test">It is example text</text>
 </svg>
</code>```

In Javascript I've got something like that:

```<code>var obj = document.getElementById('test').childNodes[1];
var box = obj.getBBox();

var centerPoint = new Object();
centerPoint.x = box.x + box.width / 2;
centerPoint.y = box.y + box.height/ 2;
</code>```

but it doesn't work - the center point is lower than I expected. Probably I missed something, I'm sure there is one more text attribute that I have to substract from "centerPoint.y". The "centerPoint.x" value seems to be OK. It's checked on IE9 browser, Chrome, Opera and Firefox. Results are the same.

Or maybe you've got other solution?

Edit

To sum up my code works properly. I rewrote whole code and it's ok now. I don't know what happend, probably my browser didn't refresh scripts at all. Setting line-height to "0" is unnecessary. getBBox it's all that I need to do that.

Anyway thank for your time and sorry for my English! :)

答:
you can use getBoundingClientRect() in place of getBBox()

```<code>var obj = document.getElementById('test').childNodes[1];
var box = obj.getBoundingClientRect();
var centerPointX = box.left + box.width / 2;
var centerPointY = box.top + box.height/ 2;
</code>```

Body:
I've got problem with SVG text element. I want to find the center point of SVG text. In HTML file:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <text x="300" y="300" style="font-size: 80px;" id="test">It is example text</text>
 </svg>

In Javascript I've got something like that:

var obj = document.getElementById('test').childNodes[1];
var box = obj.getBBox();

var centerPoint = new Object();
centerPoint.x = box.x + box.width / 2;
centerPoint.y = box.y + box.height/ 2;

but it doesn't work - the center point is lower than I expected. Probably I missed something, I'm sure there is one more text attribute that I have to substract from "centerPoint.y". The "centerPoint.x" value seems to be OK. It's checked on IE9 browser, Chrome, Opera and Firefox. Results are the same.

Or maybe you've got other solution?

Edit

To sum up my code works properly. I rewrote whole code and it's ok now. I don't know what happend, probably my browser didn't refresh scripts at all. Setting line-height to "0" is unnecessary. getBBox it's all that I need to do that.

Anyway thank for your time and sorry for my English! :)

Body:
you can use getBoundingClientRect() in place of getBBox()

var obj = document.getElementById('test').childNodes[1];
var box = obj.getBoundingClientRect();
var centerPointX = box.left + box.width / 2;
var centerPointY = box.top + box.height/ 2;


问:
Adding parameter to application root URL in WebForms
I'm trying to find a way to add parameter to script tag, which has to start with application root. What's the correct syntax for scenario below (not rendering in this form):

```<code><script type="text/javascript" runat="server" src="~/Scripts/utilities.js?v=<%$ MYAPP.Common.MainSettings.ApplicationVersion %>"></script>
</code>```

I'd like to keep this code on aspx and not move it to code-behind class.

答:
You can start the path with / instead of ~/

```<code><script type="text/javascript" runat="server" src="/Scripts/utilities.js?v=<%$ MYAPP.Common.MainSettings.ApplicationVersion %>"></script>
</code>```

You can also use ResolveUrl

```<code><script src="<%# ResolveUrl("~/Scripts/utilities.js?v=" + MYAPP.Common.MainSettings.ApplicationVersion) %>" type="text/javascript"></script>
</code>```

Body:
I'm trying to find a way to add parameter to script tag, which has to start with application root. What's the correct syntax for scenario below (not rendering in this form):

I'd like to keep this code on aspx and not move it to code-behind class.

Body:
You can start the path with / instead of ~/

<script type="text/javascript" runat="server" src="/Scripts/utilities.js?v=<%$ MYAPP.Common.MainSettings.ApplicationVersion %>"></script>

You can also use ResolveUrl

<script src="<%# ResolveUrl("~/Scripts/utilities.js?v=" + MYAPP.Common.MainSettings.ApplicationVersion) %>" type="text/javascript"></script>


问:
boost::counting_iterator analogue in range-v3
I am wondering if range-v3 library has any view/utility providing the functionality similar to boost::counting_iterators?

I was looking for something of that kind, but seems there is nothing readily available. But the documentation is incomplete (at least the README suggests so) so maybe there is something I have overlooked.

UPD: what I am actually looking for is not just a range of integers like view::iota but rather a range view (wrapper) that accepts any Incrementable.
One such example is the following code from Boost.CountingIterator documentation:

```<code>int N = 7;
std::vector<int> numbers;
...
// the code below does what I am actually looking for
// I would like to use a single range instead of two separate iterators here
std::vector<std::vector<int>::iterator> pointers;
std::copy(boost::make_counting_iterator(numbers.begin()),
          boost::make_counting_iterator(numbers.end()),
          std::back_inserter(pointers));
</code>```

答:
You do, in fact, want view::iota. It accepts any WeaklyIncrementable type for the range iterator type (not only integral types), and any type that is WeaklyEqualityComparable to that type as the range sentinel. So view::iota(0, 8) is the range of integers {0,1,2,3,4,5,6,7}, and view::iota(i, s) is the range of iterators {i,i+1,i+2,...,s}. The boost counting_iterator example translates to range-v3 as (DEMO):

```<code>int N = 7;
std::vector<int> numbers = ranges::view::iota(0, N);

std::vector<std::vector<int>::iterator> pointers =
    ranges::view::iota(numbers.begin(), numbers.end());

std::cout << "indirectly printing out the numbers from 0 to " << N << '\n';
ranges::copy(ranges::view::indirect(pointers),
    ranges::ostream_iterator<>(std::cout, " "));
std::cout << '\n';
</code>```

Body:
I am wondering if range-v3 library has any view/utility providing the functionality similar to boost::counting_iterators?

I was looking for something of that kind, but seems there is nothing readily available. But the documentation is incomplete (at least the README suggests so) so maybe there is something I have overlooked.

UPD: what I am actually looking for is not just a range of integers like view::iota but rather a range view (wrapper) that accepts any Incrementable.
One such example is the following code from Boost.CountingIterator documentation:

int N = 7;
std::vector<int> numbers;
...
// the code below does what I am actually looking for
// I would like to use a single range instead of two separate iterators here
std::vector<std::vector<int>::iterator> pointers;
std::copy(boost::make_counting_iterator(numbers.begin()),
          boost::make_counting_iterator(numbers.end()),
          std::back_inserter(pointers));

Body:
You do, in fact, want view::iota. It accepts any WeaklyIncrementable type for the range iterator type (not only integral types), and any type that is WeaklyEqualityComparable to that type as the range sentinel. So view::iota(0, 8) is the range of integers {0,1,2,3,4,5,6,7}, and view::iota(i, s) is the range of iterators {i,i+1,i+2,...,s}. The boost counting_iterator example translates to range-v3 as (DEMO):

int N = 7;
std::vector<int> numbers = ranges::view::iota(0, N);

std::vector<std::vector<int>::iterator> pointers =
    ranges::view::iota(numbers.begin(), numbers.end());

std::cout << "indirectly printing out the numbers from 0 to " << N << '\n';
ranges::copy(ranges::view::indirect(pointers),
    ranges::ostream_iterator<>(std::cout, " "));
std::cout << '\n';


问:
Tutorials to customize Tableau legend
Here is my Data Viz

I wish to customize legends as below

Here is what I have. Having difficulty finding tutorials (on google) for customizing legends. Please assist.

答:
It is difficult to making color and shap both are in legends.but it is possible we have to create new sheet and making customize legends.

Refer this site :

http://www.analytics-tuts.com/manual-legends-tableau/

I hope you helpfull this site........

Title: Tutorials to customize Tableau legend


问:
SQL Server 2005 Foreign Keys and Indices
I have a general question regarding table indices on foreign keys in database modeling. If I have a table, TABLE_A, created as:

```<code>CREATE TABLE [dbo].[TABLE_A](
 [ID] [int] IDENTITY(1,1) NOT NULL,
    [RelatedTableBID] [int] NOT NULL,
    CONSTRAINT [PK__TABLE_A] PRIMARY KEY CLUSTERED
    (
      [ID] ASC
     ) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
     IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
     ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TABLE_A]  WITH CHECK
ADD  CONSTRAINT [TABLE_A__RelatedTableB]
FOREIGN KEY([RelatedTableBID])
REFERENCES [dbo].[TABLE_B] ([ID])
</code>```

and Table_B as:

```<code>CREATE TABLE [dbo].[TABLE_B](
 [ID] [int] IDENTITY(1,1) NOT NULL,
    CONSTRAINT [PK__TABLE_B] PRIMARY KEY CLUSTERED
    (
      [ID] ASC
     ) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
     IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
     ON [PRIMARY]
) ON [PRIMARY]
</code>```

Will it in practice be more efficient if I create an index on the referencing table (Table A) referencing column (RelatedTableBID)? As in:

```<code>CREATE INDEX TABLE_A_FK_INDEX1 on TABLE_A(RelatedTableBID)
</code>```

Or am I thinking about this backwards? It seems that since the column being referenced is itself a clustered index, there shouldn't be any issues during joins - if anything, only deletes from TABLE_B seem susceptible to poor performance.

Thanks for any help in setting me straight.

-Mustafa

EDIT

So, in general, if I'm ever joining on or using a column in a where clause consistently when querying, should I consider adding an index on it? What are some best practices and "rules of thumb" for creating database indexes? Sounds like that's a generally sound decision.

答:
No.  What you're looking for is a third table.  If it's a many-to-many relationship you're looking to build, it's not possible to do without a disgustingly ineffecient DB design without a third table.

Thus:
Table 'users':  uid, first, middle, last
Table 'addresses':  aid, street, city, state, country, etc.
Table 'users-addresses':  id, uid, aid

Then you can make many to many associations in the third table.  This is typically called database normalization.

So then your query associative query would look something like:

SELECT * FROM users,addresses JOIN users-addresses ON users.uid=users-addresses.uid AND addresses.aid = users-addresses.aid WHERE users.uid='1'    or something like that

..would give you all user information and addresses for user '1'

ContentLicense: CC BY-SA 2.5

Body:
I have a general question regarding table indices on foreign keys in database modeling. If I have a table, TABLE_A, created as:

CREATE TABLE [dbo].[TABLE_A](
 [ID] [int] IDENTITY(1,1) NOT NULL,
    [RelatedTableBID] [int] NOT NULL,
    CONSTRAINT [PK__TABLE_A] PRIMARY KEY CLUSTERED
    (
      [ID] ASC
     ) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
     IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
     ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TABLE_A]  WITH CHECK
ADD  CONSTRAINT [TABLE_A__RelatedTableB]
FOREIGN KEY([RelatedTableBID])
REFERENCES [dbo].[TABLE_B] ([ID])

and Table_B as:

CREATE TABLE [dbo].[TABLE_B](
 [ID] [int] IDENTITY(1,1) NOT NULL,
    CONSTRAINT [PK__TABLE_B] PRIMARY KEY CLUSTERED
    (
      [ID] ASC
     ) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
     IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
     ON [PRIMARY]
) ON [PRIMARY]

Will it in practice be more efficient if I create an index on the referencing table (Table A) referencing column (RelatedTableBID)? As in:

CREATE INDEX TABLE_A_FK_INDEX1 on TABLE_A(RelatedTableBID)

Or am I thinking about this backwards? It seems that since the column being referenced is itself a clustered index, there shouldn't be any issues during joins - if anything, only deletes from TABLE_B seem susceptible to poor performance.

Thanks for any help in setting me straight.

-Mustafa

EDIT

So, in general, if I'm ever joining on or using a column in a where clause consistently when querying, should I consider adding an index on it? What are some best practices and "rules of thumb" for creating database indexes? Sounds like that's a generally sound decision.


问:
how to display a hidden table when submit button is clicked and data is inserted in database table in php?
I have one from through which I am entering project name and sheet name which will be saved in project table. Based on this I am inserting empty values on another table 'Data'. I am using editable table to update these empty values in database. I want to hide this table till project name and sheet name is submitted and once value is submitted then only table will be displayed. I have tried a lot but after clicking submit button my table gets displayed till page is reloaded and disappers when loading is completed. My code parts are like below.</p>

```<code>    <script>
     $(function(){
     $('button#showit').on('click',function(){
    $('#myform').show();
     });
     });
    </script>
    <form class="form-horizontal" action="db.php" id="#form1"
     onSubmit="function();" method="post">

    <input type="text" class="form-control1" name="projectname"
   id="projectname" required >
    <input type="text" class="form-control1" name="sheetname" id="sheetname"
    required >
    <button type="submit" name="submit" id="button" class="btn-
     success btn" >Submit</button>
        </form>
      <div class="tab-content"  id="myform" style="display:none">
     <div class="tab-pane active" id="horizontal-form">
     <?php

       $s4 = "SELECT * FROM data ORDER BY data_id DESC LIMIT 1";
     $res = mysqli_query($bd, $s4);
    while ($row = mysqli_fetch_array($res))
                                 {
                            ?>
   <table class="table table-bordered" style="width:50%;">
    <thead>
    <tr>
    <th>Sr.no</th>
    <th>Column Name</th>

       </tr>
     </thead>
     <tbody>

   <tr class="odd">
    <td>1</td>
     <td id="d1:<?php echo $row['data_id']; ?>" contenteditable="true"><?php
    echo $row['d1']; ?></td>
   </tr>

   .
   .
    .
   </tbody>
    </table>
   <?php } ?>
   </div>
   </div>
 on db.php I have used to get back on my previous page
    <script>
                    alert('Sheet Created Successfully');
                    window.location.href='index.php?success';

   </script>
</code>```

答:
        Site

```

Body:
I have one from through which I am entering project name and sheet name which will be saved in project table. Based on this I am inserting empty values on another table 'Data'. I am using editable table to update these empty values in database. I want to hide this table till project name and sheet name is submitted and once value is submitted then only table will be displayed. I have tried a lot but after clicking submit button my table gets displayed till page is reloaded and disappers when loading is completed. My code parts are like below.

    <form class="form-horizontal" action="db.php" id="#form1"
     onSubmit="function();" method="post">

    <input type="text" class="form-control1" name="projectname"
   id="projectname" required >
    <input type="text" class="form-control1" name="sheetname" id="sheetname"
    required >
    <button type="submit" name="submit" id="button" class="btn-
     success btn" >Submit</button>
        </form>

     <?php

       $s4 = "SELECT * FROM data ORDER BY data_id DESC LIMIT 1";
     $res = mysqli_query($bd, $s4);
    while ($row = mysqli_fetch_array($res))
                                 {
                            ?>

    Sr.no
    Column Name

    1
     <td id="d1:<?php echo $row['data_id']; ?>" contenteditable="true"><?php
    echo $row['d1']; ?>

   .
   .
    .

   <?php } ?>

 on db.php I have used to get back on my previous page

Body:
<!-- Example of jQuery Reference -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<!-- Your Hiding Script -->
<script type='text/javascript'>
    $(document).ready(function(){
      $("#AddNewRecord").hide();
    });
</script>

<!-- Your Markup -->
<table border="1" cellpadding="2" id="AddNewRecord">
    <tr style="width:25px;">
        <td>Site</td>
    </tr>
</table>


问:
TortoiseGit Graph does not show expected branching
Problem: The graph from TortoiseGit show log does not show the branching as expected. The development branch change color half way! From the steps below, it looks like it changes color at step 4 (from red to green)! How can I make sure it use just one color? (Please note that I would like to see all branches at the same time.)

Here are steps to reproduce:

Put production source code. Commit. (Bottom line 1.)

Create development branch. (Bottom line 2.)

Create a feature branch (out of development branch). Make change and
commit. (Bottom line 2.)

Merge feature branch to development branch.  (Bottom line 3.)

Create UAT branch. Fix bug. Commit.  (Bottom line 4.)

Merge UAT branch to development branch.  (Bottom line 5.)

Merge UAT branch to master branch.  (Bottom line 6.)

Let's take a look at original graph.

My coworker recreate the case using SourceTree. SourceTree merges UAT to both master and development branch at the same time. Here is the graph in SourceTree:

View it in TrotoiseGit

答:
Simply click on master in upper left corner of the TortoiseGit log: you can then select another branch.

That way, your graph will be centered to that other branch like develop.


问:
how to create an asynchronous connection to the server without sending and ajax request after every 2 seconds
I created a message chat application with JQuery. But my app is crashing due to the number of Ajax request and sending to the server.
I tried increasing the time interval but the app was no more getting messages in real time.</p>

答:
You can use socket.io, and call for fill msgs on the basis of user typo only, means when other starts typing then ajax will call otherwise not. and for notification you can use Firebase.

You can follow
https://www.thepolyglotdeveloper.com/2016/01/creating-a-real-time-chat-application-with-ionic-2-and-socket-io/

I think this will help you


问:
Deflate data decompression zlib
I'm working with zlib and have some problem with decompression. I try to decompress packets that come to "inflate" function but "inflate" returns me -3. Combination of 00 00 00 ff ff tell me that data is compressed by deflate  algorithm. So i try to decompress data with decompressor  parameters MAX_WBITS,-MAX_WBITS,30 but it did not help. Ho can i solve this problem?
Data example:

```<code>ab 17 03 01 0c 39 6d 77 78 bd 1b 14 2e 6e c5 ff
51 8f 85 cc 76 30 52 98 ed 10 aa 73 ae 5b a4 df
97 af 90 15 44 c3 74 10 de e6 1b 63 f2 ee a5 31
24 c6 01 4b 18 a9 aa 6f 95 5f 3a c0 85 ed 62 48
07 a9 0c d0 3e 97 d1 7e ca 59 42 15 47 c7 9a 75
5a 4e 12 06 08 dc 22 45 89 c3 45 c0 fc ee 74 f3
8b 76 26 c9 33 e5 5a dc d6 68 2c 11 14 bd b4 51
cd 54 92 68 82 f1 ac aa bb 94 e3 91 9b 3c 77 1d
e7 59 d7 e0 b9 e2 71 bb 05 f2 5c 9e 86 0e 22 b0
76 7f 91 88 85 1b 53 b2 0c 0c be d4 6d 69 6e 41
d6 61 c4 1a 1b d9 18 a0 24 48 1b c9 71 57 e2 d8
53 40 95 05 d0 12 97 99 a9 42 f3 d7 09 56 49 96
be e3 dd fa d4 1c 07 71 f4 dc 5e 18 a0 f4 e4 eb
5a 58 32 86 e3 7b 42 d7 39 71 85 42 74 5a 6b 0a
5f bb 89 dd 6d f1 fd ac f1 ba 92 3d e0 3f e6 48
5a 80 b5 99 27 84 bb 31 0b e5 7e 71 e6 a6 4b 4e
72 67 16 dd 45 2a 2e a2 bf c7 f4 66 de a4 5c cb
9d 30 4c fb 34 44 3e 22 a6 0a 56 62 9a 71 df 94
79 f1 53 88 59 85 73 65 55 6b 48 69 26 0d e7 2e
1d 23 7b ad 85 47 51 d4 c1 a4 a6 b0 f1 06 c8 f0
03 37 5f 00 9b 92 09 c4 89 83 9d 96 66 88 d0 f6
c5 e1 d0 f6 c2 5a ce da b0 16 2e c3 b2 7f f1 38
ac 7e 8c 8c 66 86 c2 14 65 24 e4 d2 70 73 58 46
80 b9 3c a4 4d f7 1c b5 e2 7a 7f e5 d4 0b 8b 08
26 6c 8c c1 3d 85 dc 0f 1e 3b cf da bf e2 1c 81
63 03 94 b7 14 11 56 87 dd c1 2d eb 4f 3f 0a fe
da 59 ad 89 60 eb 85 ce 6b 85 8f 33 da 33 11 fc
8f a4 f0 a2 85 a4 c0 ba 6e 57 9d 24 d5 df 97 61
24 8c 53 00 fd f5 c2 2f 7c a9 ec d2 42 3d 0c 81
4a 5e ba a5 1a 24 b9 7f 8a df 88 8d cd f0 45 f0
37 75 c2 a9 03 3a 5a c3 ed 2c b5 2d f4 43 81 4e
c4 6f 18 f0 62 74 e4 c0 5a fa 1c 66 55 92 87 ca
c5 a5 ac f2 46 4c 75 49 3b 3e 43 29 88 ee 9d 1f
79 fe 61 37 24 66 2a 8f 1a 3c e0 3c c1 cc bb f5
6a f9 54 49 19 52 45 43 a8 18 1c c2 f3 25 e3 73
a6 4d f7 63 a8 b8 2c 69 fe 65 af 2a 4e e9 6d 62
e5 86 2e 3c ae 2d 24 0d 71 f4 f7 1f eb 3d 6c 7e
ee e5 16 e6 a7 e6 74 bf 89 e5 6a f0 97 04 e5 3d
a7 1d 15 ad 9b 00 21 aa f2 44 93 18 49 c9 1a 30
ba 3d e4 99 21 86 b2 2c 43 64 62 94 58 1a 3f 13
bf a5 2d 29 3f 63 66 aa e2 2f e1 86 62 a2 8f 3d
05 4c b9 99 21 33 ff 10 9c 28 ef 4e 33 de b6 b0
86 e7 53 88 d0 f5 10 6f 39 2e ab f5 d2 fa 05 41
b9 d9 01 ed 98 01 3a 3b 07 b0 e9 f5 0e 90 c2 84
94 80 e9 f4 03 33 1c ea 10 37 68 7c 2b 29 2d 4c
d0 e2 ea 21 c4 ef 58 a1 bb a3 81 07 77 f5 3e 2c
a2 89 af db 08 47 ba d3 17 2e 1c b3 92 9c c4 de
c0 27 bd 24 74 29 b3 69 1e 60 78 13 e0 49 c9 7a
df 83 c9 86 cc 10 ce 2f d3 80 6d d9 61 f7 9b ee
90 7f e3 b4 66 7a 66 8f 0b 1a 9e b9 6d 51 9c d6
af 59 af 9f b9 9f 78 35 63 5f 03 4a d3 89 f7 71
ab 23 52 e8 2b 91 53 7c 01 2e fd 59 25 e3 99 b0
21 74 a6 dd 78 bb 48 5e 11 1e 9a 8d 93 a6 a0 a1
6c 72 eb 73 af 44 76 11 3e a5 8c 02 42 9b 72 40
52 7b 1a 66 e8 0f 6c 39 42 bf 14 04 2b 70 72 8f
b2 43 9b 56 7e 43 1d bc 5d 78 60 ab b4 94 a6 f2
00 fa 28 cd 7a 1e cf 8c f5 da 82 19 ba 11 4f 74
0e c0 00 59 0b 60 a3 56 08 e0 6b 72 3b 33 f2 bf
9a ae 76 80 a9 f4 d8 6b ef eb 52 a2 ca 20 a1 5e
26 6f 69 40 4a da 91 e4 7b 10 42 52 6e 63 13 91
68 6b 36 61 20 a9 6d e5 e5 04 50 00 eb b3 6d 10
9e f5 47 36 ca c3 d2 76 23 56 71 13 4b b2 7c 5b
b2 89 db 28 92 70 e1 f4 f5 b3 2e 9d 84 f5 87 3f
c6 05 0b b2 c9 99 cc 5b c0 b6 cc 8b 3d 5d eb 01
8f 7e 69 ac 95 bc fb 81 58 d5 01 76 a2 10 98 05
bb 7a 84 73 80 c9 61 7a 6d ce d0 db e2 0f 8c 55
73 ff ff 9c 20 3a 39 bb a9 3a df ab 35 a6 ae fb
48 45 1c 5a 5e 7b 4b f9 39 f2 51 08 59 cc a4 8f
59 ed d6 c9 e1 91 62 ec 5e 65 73 42 d7 ac 9b 67
1b 43 41 e4 1b 93 86 2e 3d af a4 83 9b f6 32 7b
bc e8 e4 60 3a 47 8e 3e 13 7d d3 74 1b 83 86 8e
c4 01 70 21 a5 d5 5c f7 22 54 e0 af be 2c c1 66
03 a0 fb 25 9c b1 90 dd 9d 78 a8 86 34 0a ee 83
d1 63 30 6e 6f de 7d 52 e6 28 ac e3 09 ab 16 f9
3b 1e fa 9f 28 dc f5 e4 bf 0f 1f 3a fc ec 60 b5
6c 7b 80 de 08 0b c5 fe b7 46 d1 23 f0 74 b5 ca
c3 85 77 76 1a 19 65 0c ec 0d a7 c5 61 ef fa 5a
7b f6 d9 14 20 a7 1b 07 f2 0f 3f 5f a8 89 17 be
78 e8 5a 1b 7c 5e 26 18 af e4 43 1d 54 d0 77 56
c5 dc 19 16 3e 1d 08 58 8e 65 a1 87 c7 0a af b8
b8 62 e9 f0 56 d3 f9 56 90 07 db 34 f6 71 78 73
e9 10 14 e6 ee 8c 59 a4 97 a5 dd f3 6a 50 c6 9f
d9 a0 d8 0c e4 12 f2 ed 2d 7e 92 8e 51 6b 7b b7
36 53 33 76 a5 ab 85 95 f9 5e 0d 5f 64 65 00 07
21 eb d0 ea c2 72 7d ab 91 b5 87 91 b8 ab 24 f6
2b 7f 16 fc 42 00 00 00 00 ff ff
</code>```

Code example:

```<code>__int32 ZLIB::Decoder(unsigned __int8* PDU, unsigned __int32 size, unsigned __int32 out_buf_size, unsigned __int8 * out_b, z_stream_s & stream, bool & IsInit, unsigned __int32 mode, __int32 max_w_bits)
{
    if (IsDllLoaded == false || PDU == nullptr) { return 0; }//if Zlib DLL was not loaded, or incoming packet is not cTCP

    if ( !IsInit )
    {
        SecureZeroMemory(&stream, sizeof(stream));
        auto res = InitZDecompressor( &stream, max_w_bits , "1.2.11", sizeof(z_stream_s));//initialize only one time
        IsInit = true;
    }

    stream.next_in = PDU;
    stream.avail_in = size;
    stream.next_out = out_b;
    stream.avail_out = out_buf_size;
    stream.total_out = 0;

    __int32 ret = 0;
    while ( stream.avail_in && ret == 0  )
    {
        ret = ZDecompressor(&stream, mode);

    }
    return ret;
}

void ZLIB::ResetDecompessor(bool & isInit, z_stream_s & stream)
{
    if (isInit)
    {
        ResetZDecompressor(&stream);
        isInit = false;
        memset(&stream, 0 ,sizeof(stream));
    }
}
</code>```

答: Your assumption is incorrect. That is not a deflate-compressed stream.</p>

Title: Deflate data decompression zlib

Body:
I'm working with zlib and have some problem with decompression. I try to decompress packets that come to "inflate" function but "inflate" returns me -3. Combination of 00 00 00 ff ff tell me that data is compressed by deflate  algorithm. So i try to decompress data with decompressor  parameters MAX_WBITS,-MAX_WBITS,30 but it did not help. Ho can i solve this problem?
Data example:

ab 17 03 01 0c 39 6d 77 78 bd 1b 14 2e 6e c5 ff
51 8f 85 cc 76 30 52 98 ed 10 aa 73 ae 5b a4 df
97 af 90 15 44 c3 74 10 de e6 1b 63 f2 ee a5 31
24 c6 01 4b 18 a9 aa 6f 95 5f 3a c0 85 ed 62 48
07 a9 0c d0 3e 97 d1 7e ca 59 42 15 47 c7 9a 75
5a 4e 12 06 08 dc 22 45 89 c3 45 c0 fc ee 74 f3
8b 76 26 c9 33 e5 5a dc d6 68 2c 11 14 bd b4 51
cd 54 92 68 82 f1 ac aa bb 94 e3 91 9b 3c 77 1d
e7 59 d7 e0 b9 e2 71 bb 05 f2 5c 9e 86 0e 22 b0
76 7f 91 88 85 1b 53 b2 0c 0c be d4 6d 69 6e 41
d6 61 c4 1a 1b d9 18 a0 24 48 1b c9 71 57 e2 d8
53 40 95 05 d0 12 97 99 a9 42 f3 d7 09 56 49 96
be e3 dd fa d4 1c 07 71 f4 dc 5e 18 a0 f4 e4 eb
5a 58 32 86 e3 7b 42 d7 39 71 85 42 74 5a 6b 0a
5f bb 89 dd 6d f1 fd ac f1 ba 92 3d e0 3f e6 48
5a 80 b5 99 27 84 bb 31 0b e5 7e 71 e6 a6 4b 4e
72 67 16 dd 45 2a 2e a2 bf c7 f4 66 de a4 5c cb
9d 30 4c fb 34 44 3e 22 a6 0a 56 62 9a 71 df 94
79 f1 53 88 59 85 73 65 55 6b 48 69 26 0d e7 2e
1d 23 7b ad 85 47 51 d4 c1 a4 a6 b0 f1 06 c8 f0
03 37 5f 00 9b 92 09 c4 89 83 9d 96 66 88 d0 f6
c5 e1 d0 f6 c2 5a ce da b0 16 2e c3 b2 7f f1 38
ac 7e 8c 8c 66 86 c2 14 65 24 e4 d2 70 73 58 46
80 b9 3c a4 4d f7 1c b5 e2 7a 7f e5 d4 0b 8b 08
26 6c 8c c1 3d 85 dc 0f 1e 3b cf da bf e2 1c 81
63 03 94 b7 14 11 56 87 dd c1 2d eb 4f 3f 0a fe
da 59 ad 89 60 eb 85 ce 6b 85 8f 33 da 33 11 fc
8f a4 f0 a2 85 a4 c0 ba 6e 57 9d 24 d5 df 97 61
24 8c 53 00 fd f5 c2 2f 7c a9 ec d2 42 3d 0c 81
4a 5e ba a5 1a 24 b9 7f 8a df 88 8d cd f0 45 f0
37 75 c2 a9 03 3a 5a c3 ed 2c b5 2d f4 43 81 4e
c4 6f 18 f0 62 74 e4 c0 5a fa 1c 66 55 92 87 ca
c5 a5 ac f2 46 4c 75 49 3b 3e 43 29 88 ee 9d 1f
79 fe 61 37 24 66 2a 8f 1a 3c e0 3c c1 cc bb f5
6a f9 54 49 19 52 45 43 a8 18 1c c2 f3 25 e3 73
a6 4d f7 63 a8 b8 2c 69 fe 65 af 2a 4e e9 6d 62
e5 86 2e 3c ae 2d 24 0d 71 f4 f7 1f eb 3d 6c 7e
ee e5 16 e6 a7 e6 74 bf 89 e5 6a f0 97 04 e5 3d
a7 1d 15 ad 9b 00 21 aa f2 44 93 18 49 c9 1a 30
ba 3d e4 99 21 86 b2 2c 43 64 62 94 58 1a 3f 13
bf a5 2d 29 3f 63 66 aa e2 2f e1 86 62 a2 8f 3d
05 4c b9 99 21 33 ff 10 9c 28 ef 4e 33 de b6 b0
86 e7 53 88 d0 f5 10 6f 39 2e ab f5 d2 fa 05 41
b9 d9 01 ed 98 01 3a 3b 07 b0 e9 f5 0e 90 c2 84
94 80 e9 f4 03 33 1c ea 10 37 68 7c 2b 29 2d 4c
d0 e2 ea 21 c4 ef 58 a1 bb a3 81 07 77 f5 3e 2c
a2 89 af db 08 47 ba d3 17 2e 1c b3 92 9c c4 de
c0 27 bd 24 74 29 b3 69 1e 60 78 13 e0 49 c9 7a
df 83 c9 86 cc 10 ce 2f d3 80 6d d9 61 f7 9b ee
90 7f e3 b4 66 7a 66 8f 0b 1a 9e b9 6d 51 9c d6
af 59 af 9f b9 9f 78 35 63 5f 03 4a d3 89 f7 71
ab 23 52 e8 2b 91 53 7c 01 2e fd 59 25 e3 99 b0
21 74 a6 dd 78 bb 48 5e 11 1e 9a 8d 93 a6 a0 a1
6c 72 eb 73 af 44 76 11 3e a5 8c 02 42 9b 72 40
52 7b 1a 66 e8 0f 6c 39 42 bf 14 04 2b 70 72 8f
b2 43 9b 56 7e 43 1d bc 5d 78 60 ab b4 94 a6 f2
00 fa 28 cd 7a 1e cf 8c f5 da 82 19 ba 11 4f 74
0e c0 00 59 0b 60 a3 56 08 e0 6b 72 3b 33 f2 bf
9a ae 76 80 a9 f4 d8 6b ef eb 52 a2 ca 20 a1 5e
26 6f 69 40 4a da 91 e4 7b 10 42 52 6e 63 13 91
68 6b 36 61 20 a9 6d e5 e5 04 50 00 eb b3 6d 10
9e f5 47 36 ca c3 d2 76 23 56 71 13 4b b2 7c 5b
b2 89 db 28 92 70 e1 f4 f5 b3 2e 9d 84 f5 87 3f
c6 05 0b b2 c9 99 cc 5b c0 b6 cc 8b 3d 5d eb 01
8f 7e 69 ac 95 bc fb 81 58 d5 01 76 a2 10 98 05
bb 7a 84 73 80 c9 61 7a 6d ce d0 db e2 0f 8c 55
73 ff ff 9c 20 3a 39 bb a9 3a df ab 35 a6 ae fb
48 45 1c 5a 5e 7b 4b f9 39 f2 51 08 59 cc a4 8f
59 ed d6 c9 e1 91 62 ec 5e 65 73 42 d7 ac 9b 67
1b 43 41 e4 1b 93 86 2e 3d af a4 83 9b f6 32 7b
bc e8 e4 60 3a 47 8e 3e 13 7d d3 74 1b 83 86 8e
c4 01 70 21 a5 d5 5c f7 22 54 e0 af be 2c c1 66
03 a0 fb 25 9c b1 90 dd 9d 78 a8 86 34 0a ee 83
d1 63 30 6e 6f de 7d 52 e6 28 ac e3 09 ab 16 f9
3b 1e fa 9f 28 dc f5 e4 bf 0f 1f 3a fc ec 60 b5
6c 7b 80 de 08 0b c5 fe b7 46 d1 23 f0 74 b5 ca
c3 85 77 76 1a 19 65 0c ec 0d a7 c5 61 ef fa 5a
7b f6 d9 14 20 a7 1b 07 f2 0f 3f 5f a8 89 17 be
78 e8 5a 1b 7c 5e 26 18 af e4 43 1d 54 d0 77 56
c5 dc 19 16 3e 1d 08 58 8e 65 a1 87 c7 0a af b8
b8 62 e9 f0 56 d3 f9 56 90 07 db 34 f6 71 78 73
e9 10 14 e6 ee 8c 59 a4 97 a5 dd f3 6a 50 c6 9f
d9 a0 d8 0c e4 12 f2 ed 2d 7e 92 8e 51 6b 7b b7
36 53 33 76 a5 ab 85 95 f9 5e 0d 5f 64 65 00 07
21 eb d0 ea c2 72 7d ab 91 b5 87 91 b8 ab 24 f6
2b 7f 16 fc 42 00 00 00 00 ff ff

Code example:

__int32 ZLIB::Decoder(unsigned __int8* PDU, unsigned __int32 size, unsigned __int32 out_buf_size, unsigned __int8 * out_b, z_stream_s & stream, bool & IsInit, unsigned __int32 mode, __int32 max_w_bits)
{
    if (IsDllLoaded == false || PDU == nullptr) { return 0; }//if Zlib DLL was not loaded, or incoming packet is not cTCP

    if ( !IsInit )
    {
        SecureZeroMemory(&stream, sizeof(stream));
        auto res = InitZDecompressor( &stream, max_w_bits , "1.2.11", sizeof(z_stream_s));//initialize only one time
        IsInit = true;
    }

    stream.next_in = PDU;
    stream.avail_in = size;
    stream.next_out = out_b;
    stream.avail_out = out_buf_size;
    stream.total_out = 0;

    __int32 ret = 0;
    while ( stream.avail_in && ret == 0  )
    {
        ret = ZDecompressor(&stream, mode);

    }
    return ret;
}

void ZLIB::ResetDecompessor(bool & isInit, z_stream_s & stream)
{
    if (isInit)
    {
        ResetZDecompressor(&stream);
        isInit = false;
        memset(&stream, 0 ,sizeof(stream));
    }
}


问:
MySQL not using ports in xampp?
I installed Joomla and updated it to the latest version, but MySQL crashed, and when I start it back up it doesn't use any ports??

I've tried restarting xampp and it doesn't fix it. After a while of MySQL being opened, it crashes and windows gives me the error:

```<code>Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: mysqld.exe
  Application Version:  10.1.21.0
  Application Timestamp:    587e81ec
  Fault Module Name:    mysqld.exe
  Fault Module Version: 10.1.21.0
  Fault Module Timestamp:   587e81ec
  Exception Code:   80000003
  Exception Offset: 00463db0
  OS Version:   6.1.7601.2.1.0.256.1
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt
</code>```

If i try going to PHPMyAdmin, it shows this :

Can I please get some help?

答: You might have some luck backing up your htdocs folder and re-installing xampp from scratch. </p>

Title: MySQL not using ports in xampp?

Body:
I installed Joomla and updated it to the latest version, but MySQL crashed, and when I start it back up it doesn't use any ports??

I've tried restarting xampp and it doesn't fix it. After a while of MySQL being opened, it crashes and windows gives me the error:

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: mysqld.exe
  Application Version:  10.1.21.0
  Application Timestamp:    587e81ec
  Fault Module Name:    mysqld.exe
  Fault Module Version: 10.1.21.0
  Fault Module Timestamp:   587e81ec
  Exception Code:   80000003
  Exception Offset: 00463db0
  OS Version:   6.1.7601.2.1.0.256.1
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

If i try going to PHPMyAdmin, it shows this :

Can I please get some help?


问:
Type ambiguity between assembly versions
I have the following line of code that generates an error:

```<code>public class AccountController : ApiController
</code>```

The error is:

CS0433    The type 'ApiController' exists in both 'System.Web.Http,
  Version=4.0.0.0, Culture=neutral,  PublicKeyToken=31bf3856ad364e35'
  and 'System.Web.Http, Version=5.2.3.0, Culture=neutral,
  PublicKeyToken=31bf3856ad364e35'

I have a very novice attempt at an assembly redirect, but how hard are they anyway?

```<code><runtime>
  <assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </assemblyBinding>
</runtime>
</code>```

The redirect seems to have no effect at all.

My current choice is to eliminate one of the versions, and I'd much prefer to dump the old 4.0.0.0, but with clashes between required libraries seem to make this difficult.

答: Your oldVersion upper limit is equal to the newVersion. Try 0.0.0.0-5.2.2.999, that may help.

Body:
I have the following line of code that generates an error:

public class AccountController : ApiController

The error is:

CS0433    The type 'ApiController' exists in both 'System.Web.Http,
  Version=4.0.0.0, Culture=neutral,  PublicKeyToken=31bf3856ad364e35'
  and 'System.Web.Http, Version=5.2.3.0, Culture=neutral,
  PublicKeyToken=31bf3856ad364e35'

I have a very novice attempt at an assembly redirect, but how hard are they anyway?

<runtime>
  <assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </assemblyBinding>
</runtime>

The redirect seems to have no effect at all.

My current choice is to eliminate one of the versions, and I'd much prefer to dump the old 4.0.0.0, but with clashes between required libraries seem to make this difficult.


问:
Sine Wave Plotting
I am trying to generate a sin wave which gets chopped regularly in a time interval of 0.004 second (the output will be a sin wave at time 0 to 0.004 seconds and then output is zero at time 0.004 second to 0.008 second.This will continue in a similar manner).

I tried the following code but it doesn't generate the correct output.

```<code>f=10000000000;
k=0;
for i=0:0.004:1
    k=k+1;
    if(mod(k,2)~=0)
        t=i:0.001:i+0.004;
        y=sin(2*3.14*f*t);
        plot(t,y);
    else
        t=i:0.001:i+0.004;
        y=0;
        plot(t,y);
    end
end
</code>```

答:
For plotting in Matlab, you want an array of x values, and a corresponding array of y values for the entire section you want to plot. So you want to first create an x array corresponding to the time from 0 to 1.004 (if I understand your code correctly), and create a y array of the same length, and populate it with the corresponding sine and 0 values.

```<code>f = 10000000000;
% generate evenly spaced x axis of 251*n+1 points evenly spaced between 0 and 1.004 (i.e. spacing between two points is 0.004/n). n should be an integer.
t = linspace(0, 1.004, 251*n+1);
% generate unchopped sine
y = sin(2*3.14*f*t);
% set desired intervals to zero
for i=1:251*n+1 % for each index in y
    % if the corresponding entry in t is a multiple of 0.008, backfill y with zeros for 0.004s.
    if(mod(t(i), 0.008)==0)
        if(i>1-n)
            for j=i-n:i
                y(j) = 0;
            end
        end
    end
end
plot(t, y)
</code>```

Title: Sine Wave Plotting

Body:
I am trying to generate a sin wave which gets chopped regularly in a time interval of 0.004 second (the output will be a sin wave at time 0 to 0.004 seconds and then output is zero at time 0.004 second to 0.008 second.This will continue in a similar manner).

I tried the following code but it doesn't generate the correct output.

f=10000000000;
k=0;
for i=0:0.004:1
    k=k+1;
    if(mod(k,2)~=0)
        t=i:0.001:i+0.004;
        y=sin(2*3.14*f*t);
        plot(t,y);
    else
        t=i:0.001:i+0.004;
        y=0;
        plot(t,y);
    end
end

Body:
For plotting in Matlab, you want an array of x values, and a corresponding array of y values for the entire section you want to plot. So you want to first create an x array corresponding to the time from 0 to 1.004 (if I understand your code correctly), and create a y array of the same length, and populate it with the corresponding sine and 0 values.

f = 10000000000;
% generate evenly spaced x axis of 251*n+1 points evenly spaced between 0 and 1.004 (i.e. spacing between two points is 0.004/n). n should be an integer.
t = linspace(0, 1.004, 251*n+1);
% generate unchopped sine
y = sin(2*3.14*f*t);
% set desired intervals to zero
for i=1:251*n+1 % for each index in y
    % if the corresponding entry in t is a multiple of 0.008, backfill y with zeros for 0.004s.
    if(mod(t(i), 0.008)==0)
        if(i>1-n)
            for j=i-n:i
                y(j) = 0;
            end
        end
    end
end
plot(t, y)


问:
How to enable scaling-up the X & Y Axis es based on the data set in C#?
I want to scale X and Y axis by considering data set in C#.

This is part of data set in .csv file

```<code>Name,Speed,Distance
Amal,20.50,100.20
Kamal,52.60,254.90
Nimal,42.00,245.00
Perera,20.30,142.00
Kasun,56.40,368.00
Piyal,45.60,784.00
Roy,45.00,521.00
Tony,25.00,36.00
Nikky,36.00,56.00
Jems,47.00,48.00
Jully,56.00,120.00
Tizz,78.00,354.00
Taly,45.00,100.00
Row,18.00,350.00
Saga,15.60,250.00
Peter,45.00,120.00
Taw,89.00,56.00
Nanny,78.60,487.00
Jumo,108.00,150.00
</code>```

This is the code that I used to plot the graph.

```<code>private void Output_Load(object sender, EventArgs e)
{

    List<Graph> ObservingData = new List<Graph>(); // List to store all available Graph objects from the CSV

    // Loops through each lines in the CSV
    foreach (string line in System.IO.File.ReadAllLines(pathToCsv).Skip(1)) // .Skip(1) is for skipping header
    {
        // here line stands for each line in the csv file

        string[] InCsvLine = line.Split(',');

        // creating an object of type Graph based on the each csv line

        Graph Inst1 = new Graph();

        Inst1.Speed = double.Parse(InCsvLine[1]);
        Inst1.Distance= double.Parse(InCsvLine[2]);

        chart1.Series["Distance"].YAxisType = AxisType.Primary;
        chart1.Series["Distance"].Points.AddXY(Inst1.Speed, Inst1.Distance);
        chart1.Series["Distance"].ChartType = SeriesChartType.FastLine;

        ChartArea CA = chart1.ChartAreas[0];
        CA.AxisX.ScaleView.Zoomable = false;
        CA.AxisY.ScaleView.Zoomable = false;
        CA.CursorX.AutoScroll = true;
        CA.CursorX.IsUserSelectionEnabled = true;

    }
}
</code>```

and this is the class that store data.

```<code>class Graph
{
    public string Name { get; set; } // property to  store Name
    public double Speed{ get; set; } // property to store Speed
    public double Distance { get; set; } // property to store Distance
}
</code>```

Now I want to scale this X and Y axis by considering data set in .csv file. Scale should be under condition.

I explain that by getting an example for that.
lets say in data set we have:

the Distance max = 784.00 & min = 36.00

then that Y axis should show values only from 33 to 787

```<code>(means + / - 0.3)
</code>```

program should be want to get Min and Max value in .csv file during in file read.

like wise think about X axis.

Can you tell me how I to code that? Any help very appreciated.

答:
Let's say that you have collection of your data points which you want to display on chart:

```<code>List<Graph> ObservingData = new List<Graph>();
</code>```

Then, the first thing you can do is to set the Minimum and Maximum for your axes, depending on the values you have:

```<code>double minY = ObservingData.Min(x => x.Distance) * 0.9;
double maxY = ObservingData.Max(x => x.Distance) * 1.1;

double minX = ObservingData.Min(x => x.Speed) * 0.9;
double maxX = ObservingData.Max(x => x.Speed) * 1.1;
</code>```

If minY = maxY = 0, then you need to set axis range manually to some specific values as required, like:

```<code>if (minY == maxY && minY == 0)
{
   minY = -0.1;
   maxY = 0.1;
}
</code>```

Then assign its values to axis.

```<code>chart1.ChartAreas[0].AxisY.Maximum = maxY;
chart1.ChartAreas[0].AxisY.Minimum = minY;
</code>```

Repeat the same steps for X axis.

AND one more thing: why you do this in loop:

```<code>    chart1.Series["Distance"].YAxisType = AxisType.Primary;
    chart1.Series["Distance"].ChartType = SeriesChartType.FastLine;

    ChartArea CA = chart1.ChartAreas[0];
    CA.AxisX.ScaleView.Zoomable = false;
    CA.AxisY.ScaleView.Zoomable = false;
    CA.CursorX.AutoScroll = true;
    CA.CursorX.IsUserSelectionEnabled = true;
</code>```

It it enough if you do it once, at the beginning, outside foreach loop.

UPDATE 13/06/2017:

Instead of max you must assign minX, maxX, minY and maxY which you have calculated above

```<code>chart1.ChartAreas[0].AxisX.Minimum = minX - 3;
chart1.ChartAreas[0].AxisX.Maximum = maxX + 3;

chart1.ChartAreas[0].AxisY.Minimum = minY - 3;
chart1.ChartAreas[0].AxisY.Maximum = maxY + 3;
</code>```

I would also suggest not to use a constant offset like you did (+/- 3), but as I said earlier, try to extend the axis range by percentages of minimum and maximum values:

```<code>double minY = ObservingData.Min(x => x.Distance) * 0.9;  // Yaxis min is 90% of Min value
double maxY = ObservingData.Max(x => x.Distance) * 1.1; // Yaxis max is 110% of Max value

double minX = ObservingData.Min(x => x.Speed) * 0.9; // like above
double maxX = ObservingData.Max(x => x.Speed) * 1.1;
</code>```

Thanks to this, you are independent of the values which you are displaying - it will be fine for both small values like 1, 0.5 etc as well as for big values like 1500.0, 99999.0.

Body:
I want to scale X and Y axis by considering data set in C#.

This is part of data set in .csv file

Name,Speed,Distance
Amal,20.50,100.20
Kamal,52.60,254.90
Nimal,42.00,245.00
Perera,20.30,142.00
Kasun,56.40,368.00
Piyal,45.60,784.00
Roy,45.00,521.00
Tony,25.00,36.00
Nikky,36.00,56.00
Jems,47.00,48.00
Jully,56.00,120.00
Tizz,78.00,354.00
Taly,45.00,100.00
Row,18.00,350.00
Saga,15.60,250.00
Peter,45.00,120.00
Taw,89.00,56.00
Nanny,78.60,487.00
Jumo,108.00,150.00

This is the code that I used to plot the graph.

private void Output_Load(object sender, EventArgs e)
{

    List<Graph> ObservingData = new List<Graph>(); // List to store all available Graph objects from the CSV

    // Loops through each lines in the CSV
    foreach (string line in System.IO.File.ReadAllLines(pathToCsv).Skip(1)) // .Skip(1) is for skipping header
    {
        // here line stands for each line in the csv file

        string[] InCsvLine = line.Split(',');

        // creating an object of type Graph based on the each csv line

        Graph Inst1 = new Graph();

        Inst1.Speed = double.Parse(InCsvLine[1]);
        Inst1.Distance= double.Parse(InCsvLine[2]);

        chart1.Series["Distance"].YAxisType = AxisType.Primary;
        chart1.Series["Distance"].Points.AddXY(Inst1.Speed, Inst1.Distance);
        chart1.Series["Distance"].ChartType = SeriesChartType.FastLine;

        ChartArea CA = chart1.ChartAreas[0];
        CA.AxisX.ScaleView.Zoomable = false;
        CA.AxisY.ScaleView.Zoomable = false;
        CA.CursorX.AutoScroll = true;
        CA.CursorX.IsUserSelectionEnabled = true;

    }
}

and this is the class that store data.

class Graph
{
    public string Name { get; set; } // property to  store Name
    public double Speed{ get; set; } // property to store Speed
    public double Distance { get; set; } // property to store Distance
}

Now I want to scale this X and Y axis by considering data set in .csv file. Scale should be under condition.

I explain that by getting an example for that.
lets say in data set we have:

the Distance max = 784.00 & min = 36.00

then that Y axis should show values only from 33 to 787

(means + / - 0.3)

program should be want to get Min and Max value in .csv file during in file read.

like wise think about X axis.

Can you tell me how I to code that? Any help very appreciated.

Body:
Let's say that you have collection of your data points which you want to display on chart:

List<Graph> ObservingData = new List<Graph>();

Then, the first thing you can do is to set the Minimum and Maximum for your axes, depending on the values you have:

double minY = ObservingData.Min(x => x.Distance) * 0.9;
double maxY = ObservingData.Max(x => x.Distance) * 1.1;

double minX = ObservingData.Min(x => x.Speed) * 0.9;
double maxX = ObservingData.Max(x => x.Speed) * 1.1;

If minY = maxY = 0, then you need to set axis range manually to some specific values as required, like:

if (minY == maxY && minY == 0)
{
   minY = -0.1;
   maxY = 0.1;
}

Then assign its values to axis.

chart1.ChartAreas[0].AxisY.Maximum = maxY;
chart1.ChartAreas[0].AxisY.Minimum = minY;

Repeat the same steps for X axis.

AND one more thing: why you do this in loop:

    chart1.Series["Distance"].YAxisType = AxisType.Primary;
    chart1.Series["Distance"].ChartType = SeriesChartType.FastLine;

    ChartArea CA = chart1.ChartAreas[0];
    CA.AxisX.ScaleView.Zoomable = false;
    CA.AxisY.ScaleView.Zoomable = false;
    CA.CursorX.AutoScroll = true;
    CA.CursorX.IsUserSelectionEnabled = true;

It it enough if you do it once, at the beginning, outside foreach loop.

UPDATE 13/06/2017:

Instead of max you must assign minX, maxX, minY and maxY which you have calculated above

chart1.ChartAreas[0].AxisX.Minimum = minX - 3;
chart1.ChartAreas[0].AxisX.Maximum = maxX + 3;

chart1.ChartAreas[0].AxisY.Minimum = minY - 3;
chart1.ChartAreas[0].AxisY.Maximum = maxY + 3;

I would also suggest not to use a constant offset like you did (+/- 3), but as I said earlier, try to extend the axis range by percentages of minimum and maximum values:

double minY = ObservingData.Min(x => x.Distance) * 0.9;  // Yaxis min is 90% of Min value
double maxY = ObservingData.Max(x => x.Distance) * 1.1; // Yaxis max is 110% of Max value

double minX = ObservingData.Min(x => x.Speed) * 0.9; // like above
double maxX = ObservingData.Max(x => x.Speed) * 1.1;

Thanks to this, you are independent of the values which you are displaying - it will be fine for both small values like 1, 0.5 etc as well as for big values like 1500.0, 99999.0.


问:
What does it mean in Spring 3, web-aware application context
I am trying to setup a session scoped bean but the spring document said that session scope is only applicable on web-aware application context.  No further explanation in the doc.  Can someone clarify this?</p>

答:
There are basically 5 types of scopes available for spring bean.
1)Singleton
2)Prototype
3)Request
4)Session
5)Global-Session

The first two scopes can be used with any type of spring applications.
But the remaining 3 are related to web applications. They can be used only with the spring applications which are involved in web.


问:
scala how to reduce while n > 0
I am wondering if there's a way to deal with a while (n > 0) loop in a more functional way, I have a small Scala app that counts the number of digits equal to K from a range from 1 to N:
for example 30 and 3 would return 4 [3, 13, 23, 30]

```<code>object NumKCount {

  def main(args: Array[String]): Unit = {
    println(countK(30,3))
  }

  def countKDigit(n:Int, k:Int):Int = {
      var num = n
      var count = 0
      while (num > 10) {
        val digit = num % 10
        if (digit == k) {count += 1}
        num = num / 10
      }
      if (num == k) {count += 1}
      count
  }

  def countK(n:Int, k:Int):Int = {
    1.to(n).foldLeft(0)((acc, x) => acc + countKDigit(x, k))
  }
}
</code>```

I'm looking for a way to define the function countKDigit using a purely functional approach

答:
What about the following approach:</p>

```<code>scala> val myInt = 346763
myInt: Int = 346763

scala> val target = 3
target: Int = 3

scala> val temp = List.tabulate(math.log10(myInt).toInt + 1)(x => math.pow(10, x).toInt)
temp: List[Int] = List(1, 10, 100, 1000, 10000, 100000)

scala> temp.map(x => myInt / x % 10)
res17: List[Int] = List(3, 6, 7, 6, 4, 3)

scala> temp.count(x => myInt / x % 10 == target)
res18: Int = 2
</code>```

Title: scala how to reduce while n > 0

Body:
I am wondering if there's a way to deal with a while (n > 0) loop in a more functional way, I have a small Scala app that counts the number of digits equal to K from a range from 1 to N:
for example 30 and 3 would return 4 [3, 13, 23, 30]

object NumKCount {

  def main(args: Array[String]): Unit = {
    println(countK(30,3))
  }

  def countKDigit(n:Int, k:Int):Int = {
      var num = n
      var count = 0
      while (num > 10) {
        val digit = num % 10
        if (digit == k) {count += 1}
        num = num / 10
      }
      if (num == k) {count += 1}
      count
  }

  def countK(n:Int, k:Int):Int = {
    1.to(n).foldLeft(0)((acc, x) => acc + countKDigit(x, k))
  }
}

I'm looking for a way to define the function countKDigit using a purely functional approach

Body:
What about the following approach:

scala> val myInt = 346763
myInt: Int = 346763

scala> val target = 3
target: Int = 3

scala> val temp = List.tabulate(math.log10(myInt).toInt + 1)(x => math.pow(10, x).toInt)
temp: List[Int] = List(1, 10, 100, 1000, 10000, 100000)

scala> temp.map(x => myInt / x % 10)
res17: List[Int] = List(3, 6, 7, 6, 4, 3)

scala> temp.count(x => myInt / x % 10 == target)
res18: Int = 2


问:
When do you have to worry about thread safety?
What are some situations where you need to worry about whether a static method is thread safe?

For example, if I have static utility function that doesn't touch any static class level variables, is that method already thread safe? If I have a static method that does touch static class variables, is that method potentially not thread safe?

Thanks in advance.

答: If you using only local stack variables in static method then there is no reason to worry. java.lang.Math.min(int, int) is good example of such method. But in case if you touching any shared static variables, or objects which do have state (aka not immutable) then you have to use synchronization.</p>